crmcutils

crmcutils is a library of “helper” tools for other crmc* packages.

Installation

crmcutils is not yet on PyPI, but you can install it directly from GitHub:

pip install git+https://github.com/KaleyWhite/crmcutils.git

Basic Use Cases

Unit Testing

Inherit from TestCaseWithSubtests to write DRYer unit tests. For example, we had this repetitive eyesore in a previous version of tests/test_output_formatting:

class OutputFormattingTest(unittest.TestCase):
    def test_format_num_positive_rational(self) -> None:
        self.assertEqual(format_num(1.61, 0.5), '1.5')

    def test_format_num_negative_irrational(self) -> None:
        self.assertEqual(format_num(-math.pi, 5), '-5')

    def test_format_num_negative_factor(self) -> None:
        self.assertRaises(ValueError, format_num, math.pi, -1)

Using TestClassWithSubtests cleaned things up significantly.

Library Function

CRMC radiation therapy treatment planning system disallows duplicate structure names, and best practices limit an structure name to 16 characters. We can use unique_naming.name_item to generate a unique name for a structure Glnd_Parathyroid among all existing structure names Glnd_Parathyroid, Glnd_Lacrimal, and LN_Neck:

name_item('Glnd_Parathyroid', ['Glnd_Parathyroid', 'Glnd_Lacrimal', 'LN_Neck'], 16)

Authors

  • Kaley White

License

Licensed under the terms of the GNU GPLv3+.