def test_roundtrip_stack(tmpdir, process_count, loaded_container_registry): definition = loaded_container_registry.findDefinitionContainers(id = "multiple_settings")[0] instances = loaded_container_registry.findInstanceContainers(id = "setting_values")[0] container_stack = ContainerStack("test_stack") container_stack.setName("Test Container Stack") container_stack.addMetaDataEntry("test", "test") container_stack.addContainer(definition) container_stack.addContainer(instances) temp_file = tmpdir.join("container_stack_test") mp_run(process_count, write_data, temp_file, container_stack) assert len(list(tmpdir.listdir())) == 1 results = mp_run(process_count, read_data, temp_file) for result in results: deserialized_stack = ContainerStack("test_stack") deserialized_stack.deserialize(result) assert deserialized_stack.getName() == container_stack.getName() assert deserialized_stack.getMetaData() == container_stack.getMetaData() assert deserialized_stack.getBottom() == container_stack.getBottom() assert deserialized_stack.getTop() == container_stack.getTop()
def test_roundtrip_stack(tmpdir, process_count, loaded_container_registry): definition = loaded_container_registry.findDefinitionContainers( id="multiple_settings")[0] instances = loaded_container_registry.findInstanceContainers( id="setting_values")[0] container_stack = ContainerStack("test_stack") container_stack.setName("Test Container Stack") container_stack.setMetaDataEntry("test", "test") container_stack.addContainer(definition) container_stack.addContainer(instances) temp_file = tmpdir.join("container_stack_test") mp_run(process_count, write_data, temp_file, container_stack) assert len(list(tmpdir.listdir())) == 1 results = mp_run(process_count, read_data, temp_file) for result in results: deserialized_stack = ContainerStack("test_stack") deserialized_stack.deserialize(result) assert deserialized_stack.getName() == container_stack.getName() assert deserialized_stack.getMetaData() == container_stack.getMetaData( ) assert deserialized_stack.getBottom() == container_stack.getBottom() assert deserialized_stack.getTop() == container_stack.getTop()
def addExtruder(self, extruder: ContainerStack) -> None: extruder_count = self.getProperty("machine_extruder_count", "value") if extruder_count and len(self._extruders) + 1 > extruder_count: Logger.log( "w", "Adding extruder {meta} to {id} but its extruder count is {count}" .format(id=self.id, count=extruder_count, meta=str(extruder.getMetaData()))) return position = extruder.getMetaDataEntry("position") if position is None: Logger.log( "w", "No position defined for extruder {extruder}, cannot add it to stack {stack}", extruder=extruder.id, stack=self.id) return if any(item.getId() == extruder.id for item in self._extruders.values()): Logger.log( "w", "Extruder [%s] has already been added to this stack [%s]", extruder.id, self._id) return self._extruders[position] = extruder
def test_findContainerStacks(container_registry, data): for container in data["containers"]: # Fill the registry with container stacks. container = container.copy() container_id = container["id"] del container["id"] container_stack = ContainerStack(container_id) for key, value in container.items(): # Copy data into metadata. container_stack.getMetaData()[key] = value container_registry.addContainer(container_stack) results = container_registry.findContainerStacks(**data["filter"]) # The actual function call we're testing. _verifyMetaDataMatches(results, data["result"])
def test_findContainerStacks(container_registry, data): for container in data["containers"]: # Fill the registry with container stacks. container = container.copy() container_id = container["id"] del container["id"] container_stack = ContainerStack(container_id) for key, value in container.items(): # Copy data into metadata. container_stack.getMetaData()[key] = value container_registry.addContainer(container_stack) results = container_registry.findContainerStacks(**data["filter"]) # The actual function call we're testing. _verifyMetaDataMatches(results, data["result"])
def _test_serialize_cycle(container_stack): name = container_stack.getName() metadata = container_stack.getMetaData() containers = container_stack.getContainers() serialised = container_stack.serialize() container_stack = ContainerStack(uuid.uuid4().int) # Completely fresh container stack. container_stack.deserialize(serialised) #ID and nextStack are allowed to be different. assert name == container_stack.getName() assert metadata == container_stack.getMetaData() assert containers == container_stack.getContainers()
def _test_serialize_cycle(container_stack): name = container_stack.getName() metadata = container_stack.getMetaData() containers = container_stack.getContainers() serialised = container_stack.serialize() container_stack = ContainerStack(uuid.uuid4().int) # Completely fresh container stack. container_stack.deserialize(serialised) #ID and nextStack are allowed to be different. assert name == container_stack.getName() assert metadata == container_stack.getMetaData() assert containers == container_stack.getContainers()
def _test_serialize_cycle(container_stack, ignored_metadata_keys: Optional[set] = None): metadata = {key: value for key, value in container_stack.getMetaData().items()} containers = container_stack.getContainers() serialised = container_stack.serialize(ignored_metadata_keys = ignored_metadata_keys) container_stack = ContainerStack(str(uuid.uuid4())) # Completely fresh container stack. container_stack.deserialize(serialised) # Remove ignored keys from metadata dict if ignored_metadata_keys: for key in ignored_metadata_keys: if key in metadata: del metadata[key] # ID and nextStack are allowed to be different. assert metadata.items() <= container_stack.getMetaData().items() assert containers == container_stack.getContainers()
def _test_serialize_cycle(container_stack, ignored_metadata_keys: Optional[set] = None): metadata = {key: value for key, value in container_stack.getMetaData().items()} containers = container_stack.getContainers() serialised = container_stack.serialize(ignored_metadata_keys = ignored_metadata_keys) container_stack = ContainerStack(str(uuid.uuid4())) # Completely fresh container stack. container_stack.deserialize(serialised) # Remove ignored keys from metadata dict if ignored_metadata_keys: for key in ignored_metadata_keys: if key in metadata: del metadata[key] # ID and nextStack are allowed to be different. assert metadata.items() <= container_stack.getMetaData().items() assert containers == container_stack.getContainers()
def addExtruder(self, extruder: ContainerStack) -> None: extruder_count = self.getProperty("machine_extruder_count", "value") if extruder_count and len(self._extruders) + 1 > extruder_count: Logger.log("w", "Adding extruder {meta} to {id} but its extruder count is {count}".format(id = self.id, count = extruder_count, meta = str(extruder.getMetaData()))) return position = extruder.getMetaDataEntry("position") if position is None: Logger.log("w", "No position defined for extruder {extruder}, cannot add it to stack {stack}", extruder = extruder.id, stack = self.id) return if any(item.getId() == extruder.id for item in self._extruders.values()): Logger.log("w", "Extruder [%s] has already been added to this stack [%s]", extruder.id, self._id) return self._extruders[position] = extruder