Ejemplo n.º 1
0
    async def test_not_saving_config_file(self):
        """Test setting SaveConfigFile to false and checking if the file is not saved."""

        test_name = 'test_not_saving_config_file'
        corpus = TestHelper.get_local_corpus(self.test_subpath, test_name)

        # Load manifest from input folder.
        manifest = await corpus.fetch_object_async('default.manifest.cdm.json')

        # Move manifest to output folder.
        output_folder = corpus.storage.fetch_root_folder('output')
        for entity_dec in manifest.entities:
            entity = await corpus.fetch_object_async(entity_dec.entity_path, manifest)
            output_folder.documents.append(entity.in_document)

        output_folder.documents.append(manifest)

        # Make sure the output folder is empty.
        TestHelper.delete_files_from_actual_output(TestHelper.get_actual_output_folder_path(self.test_subpath, test_name))

        # Save manifest to output folder.
        copy_options = CopyOptions()
        copy_options.save_config_file = False

        await manifest.save_as_async("default.manifest.cdm.json", False, copy_options)

        # Compare the result.
        TestHelper.compare_folder_files_equality(
            TestHelper.get_expected_output_folder_path(self.test_subpath, test_name),
            TestHelper.get_actual_output_folder_path(self.test_subpath, test_name))
Ejemplo n.º 2
0
    async def test_imports_for_rel_elevated_purpose_traits(self):
        """
        Testing that import for elevated purpose traits for relationships are added.
        """
        test_name = 'test_imports_for_rel_elevated_purpose_traits'
        corpus = TestHelper.get_local_corpus(self.tests_subpath, test_name)
        root_manifest = await corpus.fetch_object_async(
            'local:/default.manifest.cdm.json'
        )  # type: 'CdmManifestDefinition'
        sub_manifest = await corpus.fetch_object_async(
            root_manifest.sub_manifests[0].definition)

        await corpus.calculate_entity_graph_async(root_manifest)
        await root_manifest.populate_manifest_relationships_async(
            CdmRelationshipDiscoveryStyle.EXCLUSIVE)

        self.assertEqual('specialized/Gold.cdm.json',
                         root_manifest.imports[0].corpus_path)
        self.assertEqual('/Lead.cdm.json', sub_manifest.imports[0].corpus_path)

        corpus.storage.fetch_root_folder('output').documents.append(
            root_manifest)
        corpus.storage.fetch_root_folder('output').documents.append(
            sub_manifest)
        copy_options = CopyOptions()
        copy_options.save_config_file = False
        await root_manifest.save_as_async('output:/default.manifest.cdm.json',
                                          False, copy_options)
        # "acct.trait" in Acct.cdm.json. relationships in the manifests contain these 2 traits,
        # so the manifest should import these two entity documents, but Lead.cdm.json imports Acct.cdm.json.
        # Thus, the manifest can only import Lead.cdm.json
        await sub_manifest.save_as_async(
            'output:/default-submanifest.manifest.cdm.json', False,
            copy_options)

        TestHelper.compare_folder_files_equality(
            TestHelper.get_expected_output_folder_path(self.tests_subpath,
                                                       test_name),
            TestHelper.get_actual_output_folder_path(self.tests_subpath,
                                                     test_name))
Ejemplo n.º 3
0
    async def save_actual_entity_and_validate_with_expected(
            self,
            expected_path: str,
            actual_resolved_entity_def: CdmEntityDefinition,
            update_expected_output: bool = False) -> None:
        """Runs validation to test actual output vs expected output for attributes collection vs attribute context."""
        co = CopyOptions()
        co.save_config_file = False
        await actual_resolved_entity_def.in_document.save_as_async(
            actual_resolved_entity_def.in_document.name, options=co)
        actual_path = actual_resolved_entity_def.ctx.corpus.storage.corpus_path_to_adapter_path(
            actual_resolved_entity_def.in_document.at_corpus_path)

        with open(actual_path, 'r', encoding='utf-8') as actual_file:
            actual_ctx = actual_file.read()

        if update_expected_output:
            with open(expected_path, 'w', encoding='utf-8') as expected_file:
                expected_file.write(actual_ctx)

        with open(expected_path, 'r', encoding='utf-8') as expected_file:
            expected_ctx = expected_file.read()

        self.assertEqual(expected_ctx, actual_ctx)