class Scenario(object): @staticmethod def from_sample(relative_path): scenario = Scenario() sample_directory = join_paths(SAMPLE_DIRECTORY, relative_path) working_directory = scenario.directory # Copy all the content for item in listdir(sample_directory): source = join_paths(sample_directory, item) destination = join_paths(working_directory, item) if isdir(source): copytree(source, destination) else: copy2(source, destination) return scenario def __init__(self, path=""): temporary_directory = join_paths(mkdtemp(prefix="camp_"), path) makedirs(temporary_directory, exist_ok=True) self._input = InputDirectory(temporary_directory, YAML()) self._output = OutputDirectory(join_paths(self._input.path, "out"), YAML()) self._model = None @property def directory(self): return self._input.path @property def output_directory(self): return self._output.path @property def generated_configurations(self): _, model, warnings = self._input.model if warnings: error = ("There are warnings!\n" "\n".join(each for each in warnings)) raise AssertionError(error) return [GeneratedConfiguration(path, configuration) \ for path, configuration in self._output.existing_configurations(model)] def fetch_test_report(self): return self._output.load_reports() @property def model(self): return self._input.model def create_configuration(self, index, content): file_name = self._output._yaml_configuration_file(index) self._output.create_file(file_name, content) def create_model(self, content): self._input.create_model(content) def create_template(self, component, relative_path, content="whatever"): self._input.create_template_file(component, relative_path, content)
class Sample(object): def __init__(self, path, workspace): self._source = join_paths("samples", path) self._input = InputDirectory(self._copy(self._source, workspace), YAML()) self._output = OutputDirectory(join_paths(self._input.path, "out"), YAML()) self._model = None @staticmethod def _copy(source, workspace): destination = join_paths(workspace, basename(source)) if source and exists(source): if isdir(destination): rmtree(destination) copytree(source, destination) else: if isdir(destination): rmtree(destination) makedirs(destination) return destination @property def directory(self): return self._input.path @property def output_directory(self): return self._output.path @property def generated_configurations(self): _, model, warnings = self._input.model if warnings: error = ("There are warnings!\n" "\n".join(each for each in warnings)) raise AssertionError(error) return [GeneratedConfiguration(path, configuration) \ for path, configuration in self._output.existing_configurations(model)] @property def model(self): return self._input.model def create_configuration(self, index, content): file_name = self._output._yaml_configuration_file(index) self._output.create_file(file_name, content) def create_model(self, content): self._input.create_model(content) def create_template(self, component, relative_path, content): self._input.create_template_file(component, relative_path, content)