Example #1
0
def test_format_text_properties_no_matching_props():
    text = 'hi'
    n_text = 5
    formatted_text, text_mode = format_text_properties(text, n_text=5)
    expected_text = np.repeat(text, n_text)
    np.testing.assert_equal(formatted_text, expected_text)

    properties = {'hello': [1, 2, 3, 4, 5]}
    formatted_text, text_mode = format_text_properties(text,
                                                       n_text=5,
                                                       properties=properties)
    expected_text = np.repeat(text, n_text)
    np.testing.assert_equal(formatted_text, expected_text)
Example #2
0
def test_format_text_properties():
    text = 'name'
    n_text = 2
    properties = {
        'name': np.array(['bob', 'jane']),
        'item': np.array(['ducks', 'microscopes']),
        'weight': np.array([3, 15.123]),
    }

    formatted_text, text_mode = format_text_properties(text, n_text,
                                                       properties)
    expected_text = ['bob', 'jane']
    np.testing.assert_equal(formatted_text, expected_text)
    assert isinstance(formatted_text, np.ndarray)
Example #3
0
def test_format_text_properties_f_string():
    text = '{name} has 5 {item} that weigh {weight:.1f} kgs'
    n_text = 2
    properties = {
        'name': np.array(['bob', 'jane']),
        'item': np.array(['ducks', 'microscopes']),
        'weight': np.array([3, 15.123]),
    }

    formatted_text, text_mode = format_text_properties(text, n_text,
                                                       properties)
    expected_text = [
        'bob has 5 ducks that weigh 3.0 kgs',
        'jane has 5 microscopes that weigh 15.1 kgs',
    ]

    np.testing.assert_equal(formatted_text, expected_text)
    assert isinstance(formatted_text, np.ndarray)