Source for: test_create_test_boxes.py [raw]

 1import boxes
 2
 3
 4def test_adds_newline(tmpdir):
 5    """Test that we add a newline if the input file doesn't end in one."""
 6    # Create a temporary file with context
 7    hello = tmpdir.mkdir("sub").join("hello.txt")
 8    hello.write("hello")
 9    # No newline
10    assert hello.read() == "hello"
11
12    text_boxes = boxes.create_text_boxes(hello)
13
14    # And now we have a newline (and a soft hyphen)
15    assert "".join([b.letter for b in text_boxes]) == "hel\xadlo\n"
16
17
18def test_not_add_newline_if_repeated(tmpdir):
19    """Test that we don't add a newline if the input file ends in one."""
20    # Create a temporary file with context
21    hello = tmpdir.mkdir("sub").join("hello.txt")
22    hello.write("hello\n")
23    # No newline
24    assert hello.read() == "hello\n"
25
26    text_boxes = boxes.create_text_boxes(hello)
27
28    # And now we have a newline (and a soft hyphen)
29    assert "".join([b.letter for b in text_boxes]) == "hel\xadlo\n"
30