def test_new_page(tmpdir):
    c = chip.Chip('id', 20, rowSpacing=25.4)

    # Square page
    p = ChipGridPrinter(page_size=(2.2, 2.2), page_padding=0.1, output=tmpdir)
    assert p.page_size_pixels == (660, 660)
    assert p.page_padding_pixels == 30

    # Square chip
    chip_size = p.get_chip_size(c)
    assert chip_size == (300, 300)

    assert p.current_page == 1
    assert p.page_pos == (0, 0)

    # Row 0
    p.print_to_page(c)
    assert p.current_page == 1
    assert p.page_pos == (330, 0)

    p.save_page()
    p.new_page()
    assert p.current_page == 2
    assert p.page_pos == (0, 0)

    p.print_to_page(c)
    assert p.current_page == 2
    assert p.page_pos == (330, 0)

    assert tmpdir.join('page1.png').check(file=1)
    # Page 3 is not complete, need to save manually
    assert tmpdir.join('page2.png').check(file=0)
    p.save_page()
    assert tmpdir.join('page2.png').check(file=1)
def test_print_chips(tmpdir):
    c = chip.Chip('id', 20, rowSpacing=25.4)

    # Square page
    p = ChipGridPrinter(page_size=(2.2, 2.2), page_padding=0.1, output=tmpdir)
    assert p.page_size_pixels == (660, 660)
    assert p.page_padding_pixels == 30

    # Square chip
    chip_size = p.get_chip_size(c)
    assert chip_size == (300, 300)

    assert p.current_page == 1
    assert p.page_pos == (0, 0)

    p.print_chips([c] * 15)

    assert p.current_page == 4
    assert p.page_pos == (330, 330)

    assert tmpdir.join('page1.png').check(file=1)
    assert tmpdir.join('page2.png').check(file=1)
    assert tmpdir.join('page3.png').check(file=1)
    assert tmpdir.join('page4.png').check(file=1)