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')
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
def test_mpl_kwargs(self): expected = {'loc': 'left', 'fontstyle': 'italic'} actual = Title('timestep {num}', num=[1, 2], **expected) assert actual._mpl_kwargs == expected
def test_format_str_numpy_arrays(self): actual = Title('timestep {num}', num=np.array([1, 2])).titles assert actual == ['timestep 1', 'timestep 2']
def test_string_formatting(self): actual = Title('timestep {values:.2f}', values=[5e7]).titles assert actual == ['timestep 50000000.00']
def test_no_replacements(self): actual = Title('Name').titles assert actual == ['Name']
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']
def test_invalid_input(self): with pytest.raises(TypeError): Title(0) with pytest.raises(TypeError): Title([6, 7])
def test_list_of_str(self): labels = ['timestep 0', 'timestep 1'] result = Title(labels) assert labels == result.titles assert len(result) == 2