Example #1
0
def test_export_height_mismatch(tmpdir):
    p = utils.create_project(tmpdir, 'p', 2, 2)
    with open(p.layout_path, 'w') as f:
        Layout.create_new(f, 2, 1)

    with pytest.raises(ValueError):
        export_layout(p)
Example #2
0
def test_layout():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 1, 3)
    layout.set_value(0, 0, 'RED')
    sut = create_sut(layout, 9)

    assert sut.layout.get_value(0, 0) == 'RED'
Example #3
0
def test_set_value():
    f = create_pseudo_file('')
    sut = Layout.create_new(f, 1, 2)

    sut.set_value(0, 1, 'BLU')

    assert sut.get_value(0, 1) == 'BLU'
    verify_result(sut, f, 1, 2, [[None], ['BLU']])
Example #4
0
def test_try_clear_valid():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 1, 3)
    layout.set_value(0, 0, 'RED')
    sut = create_sut(layout, 9)

    sut.try_clear(0, 0)

    assert len(sut.circles) == 0
Example #5
0
def test_clear_value():
    f = create_pseudo_file('')
    sut = Layout.create_new(f, 1, 2)

    sut.set_value(0, 1, 'BLU')
    sut.clear_value(0, 1)

    assert sut.get_value(0, 1) is None
    verify_result(sut, f, 1, 2, [[None], [None]])
Example #6
0
def test_create_new():
    f = create_pseudo_file('')
    sut = Layout.create_new(f, 3, 2)

    assert sut.width == 3
    assert sut.height == 2
    assert sut.values == [[None, None, None], [None, None, None]]

    verify_result(sut, f, 3, 2, [[None, None, None], [None, None, None]])
Example #7
0
def test_try_set_edge():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 2, 3)
    sut = create_sut(layout, 9)

    sut.try_set(9, 0, 'RED')
    sut.try_set(0, 9, 'RED')

    assert len(sut.circles) == 0
Example #8
0
def test_export_valid(tmpdir):
    baseline_path = utils.get_baseline_path('export_valid.png')
    p = utils.create_project(tmpdir, 'p', 2, 2)
    with open(p.layout_path, 'w') as f:
        layout = Layout.create_new(f, 2, 2)
        layout.set_value(0, 0, 'BLK')
        layout.set_value(1, 0, 'WHT')
        layout.set_value(0, 1, 'BLK')

    export_layout(p)

    assert filecmp.cmp(baseline_path, p.final_path) is True
Example #9
0
def test_try_set_valid():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 1, 3)
    sut = create_sut(layout, 9)

    sut.try_set(0, 0, 'RED')

    assert len(sut.circles) == 1

    c1 = sut.circles[0]
    assert c1.fill_color == '#222222'
    assert c1.edge_color == '#333333'
Example #10
0
def verify_result(sut, f, width, height, values):
    f.seek(0)
    actual = Layout.load_from_file(f)

    # Verify the state of the object under test
    assert sut.width == width
    assert sut.height == height
    assert sut.values == values

    # Also verify the backing file to ensure coherence
    assert actual.width == width
    assert actual.height == height
    assert actual.values == values
Example #11
0
def test_circles():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 1, 3)
    layout.set_value(0, 0, 'RED')
    layout.set_value(0, 2, 'BLU')
    sut = create_sut(layout, 9)

    assert len(sut.circles) == 2

    c1 = sut.circles[0]
    assert c1.topleft == (1, 1)
    assert c1.bottomright == (7, 7)
    assert c1.diameter == 6
    assert c1.fill_color == '#222222'
    assert c1.edge_color == '#333333'

    c2 = sut.circles[1]
    assert c2.topleft == (1, 21)
    assert c2.bottomright == (7, 27)
    assert c2.diameter == 6
    assert c2.fill_color == '#555555'
    assert c2.edge_color == '#666666'
Example #12
0
def test_lines():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 2, 3)
    sut = create_sut(layout, 5)

    print()
    for line in sut.lines:
        print(f'({line.point1}) -> {line.point2}')

    assert len(sut.lines) == 3

    line1 = sut.lines[0]
    assert line1.point1 == (5, 0)
    assert line1.point2 == (5, 17)

    line2 = sut.lines[1]
    assert line2.point1 == (0, 5)
    assert line2.point2 == (11, 5)

    line3 = sut.lines[2]
    assert line3.point1 == (0, 11)
    assert line3.point2 == (11, 11)
Example #13
0
def test_create_from_file_tall():
    s = '1|2\n---\nRED'
    f = create_pseudo_file(s)
    sut = Layout.load_from_file(f)

    verify_result(sut, f, 1, 2, [[None], ['RED']])
Example #14
0
def test_create_from_file_wide():
    s = '2|1\n---|RED'
    f = create_pseudo_file(s)
    sut = Layout.load_from_file(f)

    verify_result(sut, f, 2, 1, [[None, 'RED']])
Example #15
0
def test_create_from_file_not_none():
    s = '1|1\nRED'
    f = create_pseudo_file(s)
    sut = Layout.load_from_file(f)

    verify_result(sut, f, 1, 1, [['RED']])
Example #16
0
def test_width():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 2, 3)
    sut = create_sut(layout, 5)

    assert sut.width == 11
Example #17
0
def test_height():
    f = create_pseudo_file('')
    layout = Layout.create_new(f, 2, 3)
    sut = create_sut(layout, 5)

    assert sut.height == 17