예제 #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)
    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)
예제 #3
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.])
예제 #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.])
예제 #5
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.])
예제 #6
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.])
예제 #7
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
예제 #8
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)
예제 #9
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