def test_no_shared_state(): """ See issue #11. """ grid_1 = drawing.Grid() grid_2 = drawing.Grid() i, j = 0, 0 grid_1.set_row_height(i, 1) grid_2.set_row_height(i, 2) assert grid_1.get_requested_row_height(i) == 1 assert grid_2.get_requested_row_height(i) == 2 grid_1.set_col_width(j, 1) grid_2.set_col_width(j, 2) assert grid_1.get_requested_col_width(j) == 1 assert grid_2.get_requested_col_width(j) == 2 rect_1, rect_2 = Rect.from_size(1, 1), Rect.from_size(2, 2) assert rect_1 is not rect_2 grid_1.set_min_cell_rect(i, j, rect_1) grid_2.set_min_cell_rect(i, j, rect_2) assert grid_1.get_min_cell_rect(i, j) is rect_1 assert grid_2.get_min_cell_rect(i, j) is rect_2
def test_setters(): grid = drawing.Grid() assert grid.make_claim() == (0, 0) grid.num_rows = 1 grid.default_row_height = 10 assert grid.make_claim() == (0, 10) grid.num_cols = 1 grid.default_col_width = 10 assert grid.make_claim() == (10, 10) grid.padding = 1 assert grid.make_claim() == (12, 12) grid.num_rows = 2 grid.num_cols = 2 assert grid.make_claim() == (23, 23) grid.set_min_cell_rects({(0, 0): Rect.from_size(20, 20)}) assert grid.make_claim() == (33, 33) grid.del_min_cell_rects() assert grid.make_claim() == (23, 23) grid.set_min_cell_rect(0, 0, Rect.from_size(20, 20)) assert grid.make_claim() == (33, 33) grid.del_min_cell_rect(0, 0) assert grid.make_claim() == (23, 23) grid.set_row_height(0, 20) assert grid.make_claim() == (23, 33) grid.del_row_height(0) assert grid.make_claim() == (23, 23) grid.set_col_width(0, 20) assert grid.make_claim() == (33, 23) grid.del_col_width(0) assert grid.make_claim() == (23, 23)
def test_make_claim(): grid = drawing.Grid() cells = { (0, 0): Rect.from_size(1, 2), (1, 1): Rect.from_size(3, 4), } assert grid.make_claim(cells) == (6, 8) assert grid.make_claim() == (6, 8) assert grid.min_width == 6 assert grid.min_height == 8 assert grid.min_bounding_rect == Rect(0, 0, 6, 8) grid.default_row_height = 0 grid.default_col_width = 0 assert grid.make_claim(cells) == (4, 6) assert grid.make_claim() == (4, 6) assert grid.min_width == 4 assert grid.min_height == 6 assert grid.min_bounding_rect == Rect(0, 0, 4, 6)
def test_find_cell_under_mouse(): grid = drawing.Grid() grid.num_rows = 2 grid.num_cols = 2 grid.padding = 1 grid.make_cells(Rect.from_size(5, 5)) expected_results = { (0, 0): None, (0, 1): None, (0, 2): None, (0, 3): None, (0, 4): None, (1, 0): None, (1, 1): (1, 0), (1, 2): (1, 0), (1, 3): (0, 0), (1, 4): (0, 0), (2, 0): None, (2, 1): (1, 0), (2, 2): (1, 0), (2, 3): (0, 0), (2, 4): (0, 0), (3, 0): None, (3, 1): (1, 1), (3, 2): (1, 1), (3, 3): (0, 1), (3, 4): (0, 1), (4, 0): None, (4, 1): (1, 1), (4, 2): (1, 1), (4, 3): (0, 1), (4, 4): (0, 1), } for mouse, cell in expected_results.items(): assert grid.find_cell_under_mouse(*mouse) == cell
def test_make_cells(): grid = drawing.Grid() grid.num_rows = 2 grid.num_cols = 2 expected_results = [ (Rect.from_size(10, 10), { (0, 0): Rect(0, 5, 5, 5), (0, 1): Rect(5, 5, 5, 5), (1, 0): Rect(0, 0, 5, 5), (1, 1): Rect(5, 0, 5, 5), }), (Rect.from_size(20, 20), { (0, 0): Rect(0, 10, 10, 10), (0, 1): Rect(10, 10, 10, 10), (1, 0): Rect(0, 0, 10, 10), (1, 1): Rect(10, 0, 10, 10), }), ] for bbox, cells in expected_results: assert grid.make_cells(bbox) == cells assert grid.make_cells() == cells assert grid.cell_rects == cells assert grid.bounding_rect == bbox