示例#1
0
    def test_get_original(self):

        q1 = Quantity(10, units="m", family_name="depth")
        q2 = q1.change_unit_system("IMPERIAL")
        q3 = q1.change_unit_system("METRIC")

        self.assertEqual(q1, q1.get_original(), "Original quantity's get_original method failed to return self.")
        self.assertEqual(q1, q2.get_original(), "First child get_original failed to return original.")
        self.assertEqual(q1, q3.get_original(), "Second child get_original failed to return original.")

        return
示例#2
0
    def test_get_original(self):

        q1 = Quantity(10, units='m', family_name='depth')
        q2 = q1.change_unit_system('IMPERIAL')
        q3 = q1.change_unit_system('METRIC')

        self.assertEqual(q1, q1.get_original(),
                         "Original quantity's get_original method failed to return self.")
        self.assertEqual(q1, q2.get_original(),
                         "First child get_original failed to return original.")
        self.assertEqual(q1, q3.get_original(),
                         "Second child get_original failed to return original.")

        return
示例#3
0
    def test_propagation(self):
        """ Tests data propagation for a single converted quantity. """

        q1 = Quantity(10, units="m", family_name="depth")
        q2 = q1.change_unit_system("IMPERIAL")
        q3 = q1.change_unit_system("METRIC")

        q2.data = 2 * q2.data
        q2.propagate_data_changes()

        self.assertAlmostEqual(20.0, q1.data, 1, "Propagation test expected data 20, got %s" % str(q1.data))

        q3.data = 3 * q3.data
        q3.propagate_data_changes()

        self.assertAlmostEqual(30.0, q1.data, 1, "Propagation test expected data 30, got %s" % str(q1.data))

        return
示例#4
0
    def test_propagation(self):
        """ Tests data propagation for a single converted quantity. """

        q1 = Quantity(10, units='m', family_name='depth')
        q2 = q1.change_unit_system('IMPERIAL')
        q3 = q1.change_unit_system('METRIC')

        q2.data = 2 * q2.data
        q2.propagate_data_changes()

        self.assertAlmostEqual(20., q1.data, 1,
                               "Propagation test expected data 20, got %s" % str(q1.data))

        q3.data = 3 * q3.data
        q3.propagate_data_changes()

        self.assertAlmostEqual(30., q1.data, 1,
                               "Propagation test expected data 30, got %s" % str(q1.data))

        return
示例#5
0
    def test_conversion_tracks_parents(self):
        """ Test that a _converted_from traits is set appropriately.

        Quantity converted from another quantity via change_unit_system has
        the _converted_from trait set appropriately.
        """

        metric_system = unit_manager.get_unit_system("METRIC")
        metric_depth = metric_system.units("depth")

        q1 = Quantity(32, units="m", family_name="depth")
        q2 = q1.change_unit_system("IMPERIAL")
        q3 = q2.change_unit_system("METRIC")

        self.assertEqual(q1, q2._converted_from, "Conversion failed to track conversion parent.")
        self.assertEqual(q2, q3._converted_from, "Conversion failed to track conversion parent.")

        return
    def test_conversion_tracks_parents(self):
        """ Test that a _converted_from traits is set appropriately.

        Quantity converted from another quantity via change_unit_system has
        the _converted_from trait set appropriately.
        """

        metric_system = unit_manager.get_unit_system('METRIC')
        metric_depth = metric_system.units('depth')

        q1 = Quantity(32, units='m', family_name='depth')
        q2 = q1.change_unit_system('IMPERIAL')
        q3 = q2.change_unit_system('METRIC')

        self.assertEqual(q1, q2._converted_from,
                         "Conversion failed to track conversion parent.")
        self.assertEqual(q2, q3._converted_from,
                         "Conversion failed to track conversion parent.")

        return