def test_hasattr(): class A(): def __init__(self): self.a = True variable = A() assert _hasattr(variable, "a", bool) assert not _hasattr(variable, "b", bool)
def test_area_selector(): selector = AreaSelector(params=rcParams) assert _hasattr(selector, "area", type(None)) assert _hasattr(selector, "area_first_coords", type(None)) assert _hasattr(selector, "area_last_coords", type(None)) # test with a valid area (min, max): area = np.asarray([[0, 0, 0], [1, 1, 1]]) with enabled_area_testing(selector, area): selected_area = np.asarray(selector.selection_area()) assert all(np.equal(selected_area.flatten(), area.flatten()))
def test_minimal_plotter(qtbot): plotter = MinimalPlotter() assert _hasattr(plotter, "render_widget", QVTKRenderWindowInteractor) assert _hasattr(plotter, "render_window", vtk.vtkRenderWindow) assert _hasattr(plotter, "renderer", vtk.vtkRenderer) assert _hasattr(plotter, "camera", vtk.vtkCamera) assert _hasattr(plotter, "interactor", vtk.vtkRenderWindowInteractor) qtbot.addWidget(plotter) assert not plotter.isVisible() plotter.show() assert plotter.isVisible() plotter.close()
def test_selector(): selector = Selector(params=rcParams) assert all(np.equal(selector.dimensions, [2, 2, 2])) assert _hasattr(selector, "coords", type(None)) assert _hasattr(selector, "coords_type", type) assert selector.selection() is None # requires an actor (i.e. plotter) # selector.hide() # selector.show() coords = np.asarray([0, 0, 0]) selector.select(coords) assert all(np.equal(selector.selection(), coords))
def test_symmetry_selector(): dimensions = [3, 3, 3] selector = SymmetrySelector(params=rcParams, dimensions=dimensions) assert _hasattr(selector, "selector_x", AreaSelector) assert _hasattr(selector, "selector_y", AreaSelector) assert _hasattr(selector, "selector_xy", AreaSelector) assert _hasattr(selector, "symmetry", Symmetry) assert _hasattr(selector, "dimensions", np.ndarray) for symmetry in Symmetry: selector.set_symmetry(symmetry) # test with a valid area (min, max): area = np.asarray([[0, 0, 0], [1, 1, 1]]) diff_area = area[1] - area[0] with enabled_area_testing(selector, area): selected_area = np.asarray(selector.selection_area()) assert all(np.equal(selected_area[0].flatten(), area.flatten())) for sym_area in selected_area: diff_sym_area = sym_area[1] - sym_area[0] assert all(np.equal(diff_sym_area, diff_area)) coords = np.asarray([0, 0, 0]) selected = selector.selection() assert all(np.equal(selected[0], coords))
def test_core_plotter(qtbot): black = (0, 0, 0) white = (1, 1, 1) # default parameters mesh = get_poly_data() # We set advanced=True in here but on Azure (and GA), # AA and smoothing cause segfaults (access violation) on # grid datasets. So we use PolyData but this is basically # calculated risk. plotter = CorePlotter(params=rcParams, advanced=True, testing=False) assert _hasattr(plotter, "params", dict) assert _hasattr(plotter, "show_edges", bool) assert _hasattr(plotter, "line_width", int) assert _hasattr(plotter, "window_size", list) assert _hasattr(plotter, "advanced", bool) assert _hasattr(plotter, "background_top_color", list) assert _hasattr(plotter, "background_bottom_color", list) qtbot.addWidget(plotter) plotter.set_background(color=black) plotter.set_background(color=black, top=white) plotter.show() plotter.add_mesh(mesh, rgba=True) plotter.add_mesh(mesh, rgba=False) plotter.reset_camera() plotter.close() # modified parameters mesh = get_uniform_grid() window_size = (300, 300) background_bottom_color = (0, 0, 0) background_top_color = (1, 1, 1) # we use advanced=False and testing=False)for coverage: plotter = CorePlotter( params=rcParams, window_size=window_size, background_top_color=background_top_color, background_bottom_color=background_bottom_color, advanced=False, testing=False, ) qtbot.addWidget(plotter) plotter.show() plotter.close()
def test_block(): dimensions = [3, 3, 3] mesh = get_structured_grid(dimensions=dimensions) block = Block(params=rcParams, dimensions=dimensions, mesh=mesh) assert _hasattr(block, "actor", type(None)) assert _hasattr(block, "show_edges", bool) assert _hasattr(block, "element_id", ElementId) assert _hasattr(block, "unit", float) assert _hasattr(block, "origin", np.ndarray) assert _hasattr(block, "color_array_name", str) assert _hasattr(block, "color", np.ndarray) assert _hasattr(block, "edge_color", np.ndarray) assert _hasattr(block, "merge_policy", str) assert _hasattr(block, "spacing", np.ndarray) assert _hasattr(block, "dimensions", np.ndarray) assert _hasattr(block, "number_of_cells", int) assert _hasattr(block, "mesh", vtk.vtkStructuredGrid) assert _hasattr(block, "color_array", vtk.vtkDataArray) assert _hasattr(block, "plotting", dict) plotting = block.plotting assert "mesh" in plotting assert "edge_color" in plotting assert "rgba" in plotting merge_policies = rcParams["block"]["merge_policy"]["range"] for policy in merge_policies: external_block = Block(params=rcParams, dimensions=[2, 2, 2]) external_block.add_all() for visible in [False, True]: if visible: block.add_all() else: block.remove_all() block.merge_policy = policy block.merge(external_block) assert all(block.dimensions == dimensions) block.remove_all() assert not block.mesh.IsCellVisible(0) block.add(coords=[0, 0, 0]) block.add(coords=[0, 0, 0]) assert block.mesh.IsCellVisible(0) block.remove(coords=[0, 0, 0]) block.remove(coords=[0, 0, 0]) assert not block.mesh.IsCellVisible(0) block.add(coords=([0, 0, 0], [0, 0, 1])) block.add(coords=([0, 0, 0], [0, 0, 1])) assert block.mesh.IsCellVisible(0) block.remove(coords=([0, 0, 0], [0, 0, 1])) block.remove(coords=([0, 0, 0], [0, 0, 1])) assert not block.mesh.IsCellVisible(0) block.set_color(color=(255, 255, 255), is_int=True) assert np.allclose(block.color, (1., 1., 1.))
def test_element(): value = np.random.randint(0, len(ElementId)) element_id = ElementId(value) dimensions = [2, 2, 2] white = (1., 1., 1.) opacity = 1. element = Element( params=rcParams, element_id=element_id, dimensions=dimensions, color=white, opacity=opacity, ) assert _hasattr(element, "actor", type(None)) assert _hasattr(element, "params", dict) assert _hasattr(element, "element_id", ElementId) assert _hasattr(element, "unit", float) assert _hasattr(element, "edge_color_offset", list) assert _hasattr(element, "dimensions", np.ndarray) assert _hasattr(element, "origin", np.ndarray) assert _hasattr(element, "spacing", np.ndarray) assert _hasattr(element, "center", np.ndarray) assert _hasattr(element, "color", np.ndarray) assert _hasattr(element, "edge_color", np.ndarray) assert _hasattr(element, "opacity", float) assert _hasattr(element, "mesh", vtk.vtkUniformGrid) assert _hasattr(element, "plotting", dict) assert element.element_id.value == value assert np.allclose(element.color, white) assert np.allclose(element.opacity, opacity) mesh = element.mesh assert np.allclose(mesh.GetDimensions(), dimensions) plotting = element.plotting assert "mesh" in plotting assert "color" in plotting assert "edge_color" in plotting assert "opacity" in plotting with pytest.raises(ValueError, match="actor"): element.set_block_mode(None) tr = np.asarray([0, 0, 1]) origin = element.mesh.GetOrigin() element.translate(tr) assert np.allclose(element.mesh.GetOrigin(), origin + tr)
def test_main_plotter(qtbot): plotter = MainPlotter(params=rcParams, testing=True) qtbot.addWidget(plotter) _hasattr(plotter, "unit", float) _hasattr(plotter, "default_block_color", tuple) _hasattr(plotter, "toolbar_area", str) _hasattr(plotter, "icon_size", tuple) _hasattr(plotter, "dimensions", tuple) _hasattr(plotter, "button_pressed", bool) _hasattr(plotter, "button_released", bool) _hasattr(plotter, "area_selection", bool) _hasattr(plotter, "floor", type(None)) _hasattr(plotter, "ceiling", type(None)) _hasattr(plotter, "icons", type(None)) _hasattr(plotter, "toolbar", type(None)) _hasattr(plotter, "current_block_mode", type(None)) _hasattr(plotter, "mode_functions", type(None)) _hasattr(plotter, "import_dialog", QFileDialog) _hasattr(plotter, "export_dialog", QFileDialog) _hasattr(plotter, "setting_dialog", SettingDialog) _hasattr(plotter, "help_dialog", HelpDialog) # block mode assert plotter.current_block_mode == BlockMode.BUILD assert isinstance(plotter.mode_functions, dict) assert len(plotter.mode_functions.keys()) == len(BlockMode) # load icons for category in (BlockMode, Action, Toggle, Symmetry): for element in category: assert element in plotter.icons assert plotter.icons[element] is not None # toolbar is hard to test assert plotter.toolbar is not None # load elements assert _hasattr(plotter, "block", Block) assert _hasattr(plotter, "grid", Grid) assert _hasattr(plotter, "plane", Plane) assert _hasattr(plotter, "selector", SymmetrySelector) # add elements for element_name in ["block", "grid", "plane", "selector"]: element = getattr(plotter, element_name) assert element.actor is not None assert element.actor.element_id == element.element_id for selector_name in ["x", "y", "xy"]: selector = getattr(plotter.selector, "selector_" + selector_name) assert selector.actor is not None assert selector.actor.element_id == selector.element_id # remove elements plotter.remove_elements() for element_name in ["block", "grid", "plane", "selector"]: element = getattr(plotter, element_name) assert element.actor is None for selector_name in ["x", "y", "xy"]: selector = getattr(plotter.selector, "selector_" + selector_name) assert selector.actor is None plotter.close()