Ejemplo n.º 1
0
 def __init__(self, parent, view=None):
     if view is None:
         self.view = CroppingView(parent)
     else:
         self.view = view
     self.model = CroppingModel()
     self.presenter = CroppingPresenter(self.model, self.view)
Ejemplo n.º 2
0
    def __init__(self, parent, view=None, model=None):
        self.parent = parent
        self.model = model if model else CroppingModel()
        self.view = view if view else CroppingView(parent)

        self.bank = 0
        self.custom_spectra_enabled = False
        self.custom_spectra = None
        self.spectra_valid = True
        self.custom_calfile_enabled = True
        self.custom_calfile = None
        self.calfile_valid = True

        # Connect view signals to local functions
        self.view.set_on_combo_changed(self.on_combo_changed)
        self.view.set_on_custom_calfile_changed(self.on_calfile_changed)
        self.view.set_on_custom_spectra_changed(self.on_spectra_changed)

        self.on_combo_changed(0)
Ejemplo n.º 3
0
 def setUp(self):
     self.model = CroppingModel()
Ejemplo n.º 4
0
class CroppingModelTest(unittest.TestCase):
    def setUp(self):
        self.model = CroppingModel()

    def test_validate_single_valid_spectra(self):
        self.assertTrue(self.model.validate_spectrum_numbers("1,2,3,4,5,6,7,8,9,10"))

    def test_validate_single_valid_spectra_regular_whitespace(self):
        self.assertTrue(self.model.validate_spectrum_numbers("1, 2, 3, 4, 5, 6, 7, 8, 9, 10"))

    def test_validate_single_valid_spectra_irregular_whitespace(self):
        self.assertTrue(self.model.validate_spectrum_numbers("1, 2,3,4,   5,6 ,7, 8,   9,  10"))

    def test_validate_single_spectra_invalid_negative(self):
        self.assertFalse(self.model.validate_spectrum_numbers("1,2,3,4,-5,6,7,8,9,10"))

    def test_validate_single_spectra_invalid_spectrum(self):
        self.assertFalse(self.model.validate_spectrum_numbers("1,2,3,4,5,6,77777,8,9,"))

    def test_validate_ranged_spectra(self):
        self.assertTrue(self.model.validate_spectrum_numbers("1-5, 5, 3  , 2-7, 7-13"))

    def test_clean_spectrum_numbers_regular_whitespace(self):
        self.assertEqual(self.model._clean_spectrum_numbers("1, 2, 5, 76, 3"), "1,2,5,76,3")

    def test_clean_spectrum_numbers_irregular_whitespace(self):
        self.assertEqual(self.model._clean_spectrum_numbers("1 , 2, 5      ,    76, 3     "),
                         "1,2,5,76,3")

    def test_clean_spectrum_numbers_regular_ranges(self):
        self.assertEqual(self.model._clean_spectrum_numbers("1-2, 5-76, 3"), "1-2,5-76,3")

    def test_clean_spectrum_numbers_reversed_ranges(self):
        self.assertEqual(self.model._clean_spectrum_numbers("2-1, 76-5, 3"), "1-2,5-76,3")

    def test_clean_spectrum_numbers_equal_range(self):
        self.assertRaisesRegex(ValueError,
                               "Ranges cannot contain the same value twice. Invalid Range:*",
                               self.model._clean_spectrum_numbers, "1-1, 76-76, 3")

    def test_validate_and_clean_with_valid_input(self):
        self.assertEqual(self.model.validate_and_clean_spectrum_numbers("1-6, 7-23, 46, 1"),
                         ("", "1-6,7-23,46,1"))

    def test_validate_and_clean_reverse_ranges(self):
        self.assertEqual(self.model.validate_and_clean_spectrum_numbers("6-1, 7-24, 6-4,1"),
                         ("", "1-6,7-24,4-6,1"))

    def test_validate_and_clean_equal_ranges(self):
        self.assertEqual(self.model.validate_and_clean_spectrum_numbers("6-6, 7-24, 6-4,1"),
                         ("Ranges cannot contain the same value twice. Invalid Range: 6-6", ""))