Пример #1
0
 def test_incorrect_spacing(self):
     fl = ScalarFormatterLocator(unit=u.m)
     fl.spacing = 0.032 * u.m
     with pytest.warns(UserWarning,
                       match=r'Spacing is not a multiple of base spacing'):
         fl.format = 'x.xx'
     assert_almost_equal(fl.spacing.to_value(u.m), 0.03)
Пример #2
0
    def test_values(self):

        fl = ScalarFormatterLocator(values=[0.1, 1., 14.] * u.m, unit=u.m)
        assert fl.values.value.tolist() == [0.1, 1., 14.]
        assert fl.number is None
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.value, [0.1, 1., 14.])
Пример #3
0
    def test_values(self):

        fl = ScalarFormatterLocator(values=[0.1, 1., 14.] * u.m, unit=u.m)
        assert fl.values.value.tolist() == [0.1, 1., 14.]
        assert fl.number is None
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.value, [0.1, 1., 14.])
Пример #4
0
    def test_number(self):

        fl = ScalarFormatterLocator(number=7, unit=u.m)
        assert fl.values is None
        assert fl.number == 7
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.value, np.linspace(36., 54., 10))

        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, np.linspace(34.4, 36, 9))

        fl.format = 'x'
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, [35., 36.])
    def test_too_many_options(self):

        with pytest.raises(ValueError) as exc:
            ScalarFormatterLocator(values=[1., 2.] * u.m, number=5)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"

        with pytest.raises(ValueError) as exc:
            ScalarFormatterLocator(values=[1., 2.] * u.m, spacing=5. * u.m)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"

        with pytest.raises(ValueError) as exc:
            ScalarFormatterLocator(number=5, spacing=5. * u.m)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"

        with pytest.raises(ValueError) as exc:
            ScalarFormatterLocator(values=[1., 2.] * u.m, number=5, spacing=5. * u.m)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"
    def test_values_unit(self):

        # Make sure that the intrinsic unit and format unit are correctly
        # taken into account when using the locator

        fl = ScalarFormatterLocator(unit=u.cm, format_unit=u.m)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [1000., 1200., 1400., 1600., 1800., 2000.] * u.cm)

        fl = ScalarFormatterLocator(unit=u.cm, format_unit=u.m)
        fl.format = 'x.x'
        assert_quantity_allclose(fl.locator(1, 19)[0], [10] * u.cm)
Пример #7
0
    def test_spacing(self):

        fl = ScalarFormatterLocator(spacing=3. * u.m)
        assert fl.values is None
        assert fl.number is None
        assert fl.spacing == 3. * u.m

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.value, [36., 39., 42., 45., 48., 51., 54.])

        fl.spacing = 0.5 * u.m
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, [34.5, 35., 35.5, 36.])

        with pytest.warns(UserWarning, match=r'Spacing is too small'):
            fl.format = 'x'
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, [35., 36.])
    def test_minor_locator(self):

        fl = ScalarFormatterLocator(unit=u.m)

        values, spacing = fl.locator(34.3, 55.4)

        minor_values = fl.minor_locator(spacing, 5, 34.3, 55.4)

        assert_almost_equal(minor_values.value, [36., 37., 38., 39., 41., 42.,
                            43., 44., 46., 47., 48., 49., 51., 52., 53., 54.])
        print('minor_values: ' + str(minor_values))

        minor_values = fl.minor_locator(spacing, 2, 34.3, 55.4)

        assert_almost_equal(minor_values.value, [37.5, 42.5, 47.5, 52.5])

        fl.values = [0.1, 1., 14.] * u.m

        values, spacing = fl.locator(34.3, 36.1)

        minor_values = fl.minor_locator(spacing, 2, 34.3, 55.4)

        assert_almost_equal(minor_values.value, [])
Пример #9
0
    def test_number(self):

        fl = ScalarFormatterLocator(number=7, unit=u.m)
        assert fl.values is None
        assert fl.number == 7
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.value, np.linspace(36., 54., 10))

        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, np.linspace(34.4, 36, 9))

        fl.format = 'x'
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, [35., 36.])
Пример #10
0
    def test_spacing(self):

        fl = ScalarFormatterLocator(spacing=3. * u.m)
        assert fl.values is None
        assert fl.number is None
        assert fl.spacing == 3. * u.m

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.value, [36., 39., 42., 45., 48., 51., 54.])

        fl.spacing = 0.5 * u.m
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, [34.5, 35., 35.5, 36.])

        with pytest.warns(UserWarning, match='Spacing is too small'):
            fl.format = 'x'
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.value, [35., 36.])
Пример #11
0
 def test_base_spacing(self, format, base_spacing):
     fl = ScalarFormatterLocator(number=5, format=format, unit=u.m)
     assert fl.base_spacing == base_spacing
Пример #12
0
 def test_invalid_formats(self, format):
     fl = ScalarFormatterLocator(number=5, unit=u.m)
     with pytest.raises(ValueError) as exc:
         fl.format = format
     assert exc.value.args[0] == "Invalid format: " + format
Пример #13
0
 def test_format_unit(self, format, string):
     fl = ScalarFormatterLocator(number=5, format=format, unit=u.m)
     fl.format_unit = u.cm
     assert fl.formatter([15.392231] * u.m, None)[0] == string
Пример #14
0
    def test_no_options(self):

        fl = ScalarFormatterLocator(unit=u.m)
        assert fl.values is None
        assert fl.number == 5
        assert fl.spacing is None
Пример #15
0
 def test_incorrect_spacing(self):
     fl = ScalarFormatterLocator(unit=u.m)
     fl.spacing = 0.032 * u.m
     with pytest.warns(UserWarning, match='Spacing is not a multiple of base spacing'):
         fl.format = 'x.xx'
     assert_almost_equal(fl.spacing.to_value(u.m), 0.03)
Пример #16
0
 def test_invalid_formats(self, format):
     fl = ScalarFormatterLocator(number=5, unit=u.m)
     with pytest.raises(ValueError) as exc:
         fl.format = format
     assert exc.value.args[0] == "Invalid format: " + format
Пример #17
0
 def test_format_unit(self, format, string):
     fl = ScalarFormatterLocator(number=5, format=format, unit=u.m)
     fl.format_unit = u.cm
     assert fl.formatter([15.392231] * u.m, None)[0] == string