Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unit test on strings coming out of EngFormatter
Hope it is what was expected when asking for some unit (non image) test.
  • Loading branch information
afvincent committed Jun 5, 2016
commit 6f9bf5f68f7964143fde229a824f96f1705b4c0f
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,26 @@ def test_percentformatter():
yield (_percent_format_helper,) + case


def test_EngFormatter_formatting():
"""
Create two instances of EngFormatter with default parameters, with and
without a unit string ('s' for seconds). Test the formatting in some cases,
especially the case when no SI prefix is present, for values in [1, 1000).

Should not exception.
"""
unitless = pef.EngFormatter()
nose.tools.assert_equal(unitless(0.1), u'100 m')
nose.tools.assert_equal(unitless(1), u'1')
nose.tools.assert_equal(unitless(999.9), u'999.9')
nose.tools.assert_equal(unitless(1001), u'1.001 k')

with_unit = pef.EngFormatter(unit=u's')
nose.tools.assert_equal(with_unit(0.1), u'100 ms')
nose.tools.assert_equal(with_unit(1), u'1 s')
nose.tools.assert_equal(with_unit(999.9), u'999.9 s')
nose.tools.assert_equal(with_unit(1001), u'1.001 ks')

if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)