예제 #1
0
    def test_text(self):
        # TODO test that the right type of object is produced?
        title_block = Title('timestep {num}', num=[1, 2])

        ax = plt.gca()
        assert ax.get_title() == 'timestep 1'
        title_block._update(1)
        assert ax.get_title() == 'timestep 2'
        plt.close('all')
예제 #2
0
 def test_multiple_replacements(self):
     actual = Title('timestep {num}, max density {n}',
                    num=[1, 2],
                    n=[500, 10]).titles
     expected = [
         'timestep {num}, max density {n}'.format(num=1, n=500),
         'timestep {num}, max density {n}'.format(num=2, n=10)
     ]
     assert actual == expected
예제 #3
0
 def test_mpl_kwargs(self):
     expected = {'loc': 'left', 'fontstyle': 'italic'}
     actual = Title('timestep {num}', num=[1, 2], **expected)
     assert actual._mpl_kwargs == expected
예제 #4
0
 def test_format_str_numpy_arrays(self):
     actual = Title('timestep {num}', num=np.array([1, 2])).titles
     assert actual == ['timestep 1', 'timestep 2']
예제 #5
0
 def test_string_formatting(self):
     actual = Title('timestep {values:.2f}', values=[5e7]).titles
     assert actual == ['timestep 50000000.00']
예제 #6
0
 def test_no_replacements(self):
     actual = Title('Name').titles
     assert actual == ['Name']
예제 #7
0
    def test_format_str(self):
        actual = Title('timestep {num}', num=[1, 2]).titles
        assert actual == ['timestep 1', 'timestep 2']

        actual = Title('timestep {num}', num=[1]).titles
        assert actual == ['timestep 1']
예제 #8
0
 def test_invalid_input(self):
     with pytest.raises(TypeError):
         Title(0)
     with pytest.raises(TypeError):
         Title([6, 7])
예제 #9
0
 def test_list_of_str(self):
     labels = ['timestep 0', 'timestep 1']
     result = Title(labels)
     assert labels == result.titles
     assert len(result) == 2