def test_change_grid(): grid = Grid(extent=(8, 6), gpts=10) grid.sampling = .2 assert (grid.extent[0] == 8.) & (grid.extent[1] == 6.) assert (grid.gpts[0] == 40) & (grid.gpts[1] == 30) grid.gpts = 100 assert (grid.extent[0] == 8.) & (grid.extent[1] == 6.) assert (grid.sampling[0] == .08) & (grid.sampling[1] == .06) grid.extent = (16, 12) assert (grid.gpts[0] == 100) & (grid.gpts[1] == 100) assert (grid.extent[0] == 16.) & (grid.extent[1] == 12.) assert (grid.sampling[0] == .16) & (grid.sampling[1] == .12) grid.extent = (10, 10) assert (grid.sampling[0] == grid.extent[0] / grid.gpts[0]) & (grid.sampling[1] == grid.extent[1] / grid.gpts[1]) grid.sampling = .3 assert (grid.extent[0] == grid.sampling[0] * grid.gpts[0]) & (grid.extent[1] == grid.sampling[1] * grid.gpts[1]) grid.gpts = 30 assert (grid.sampling[0] == grid.extent[0] / grid.gpts[0]) & (grid.sampling[1] == grid.extent[1] / grid.gpts[1])
def test_locked_grid(): grid = Grid(gpts=200, lock_gpts=True) grid.extent = 10 assert (grid.sampling[0] == .05) & (grid.sampling[1] == .05) grid.extent = 20 assert (grid.sampling[0] == .1) & (grid.sampling[1] == .1) with pytest.raises(RuntimeError) as e: grid.gpts = 100 assert str(e.value) == 'gpts cannot be modified'
def test_grid_event(): grid = Grid() grid.extent = 5 assert grid.changed._notify_count == 1 grid.gpts = 100 assert grid.changed._notify_count == 2 grid.sampling = .1 assert grid.changed._notify_count == 3