Example #1
0
    def test_write_v4_archive(self):
        fp = os.path.join(self.temp_dir.name, 'artifact_v1.qza')

        with artifact_version(4):
            artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
                                           self.provenance_capture)
            artifact.save(fp)

        root_dir = str(artifact.uuid)
        expected = {
            'VERSION',
            'metadata.yaml',
            'data/file1.txt',
            'data/file2.txt',
            'data/nested/file3.txt',
            'data/nested/file4.txt',
            'provenance/metadata.yaml',
            'provenance/VERSION',
            'provenance/citations.bib',
            'provenance/action/action.yaml',
        }
        self.assertArchiveMembers(fp, root_dir, expected)

        with zipfile.ZipFile(fp, mode='r') as zf:
            version = zf.read(os.path.join(root_dir, 'VERSION'))
        self.assertRegex(str(version), '^.*archive: 4.*$')
Example #2
0
    def test_from_view_and_save(self):
        fp = os.path.join(self.test_dir.name, 'artifact.qza')
        # Using four-ints data layout because it has multiple files, some of
        # which are in a nested directory.
        artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
                                       self.provenance_capture)

        artifact.save(fp)

        root_dir = str(artifact.uuid)
        expected = {
            'VERSION',
            'checksums.md5',
            'metadata.yaml',
            'data/file1.txt',
            'data/file2.txt',
            'data/nested/file3.txt',
            'data/nested/file4.txt',
            'provenance/metadata.yaml',
            'provenance/VERSION',
            'provenance/citations.bib',
            'provenance/action/action.yaml'
        }

        self.assertArchiveMembers(fp, root_dir, expected)
Example #3
0
    def test_from_view_and_save(self):
        fp = os.path.join(self.test_dir.name, 'artifact.qza')
        # Using four-ints data layout because it has multiple files, some of
        # which are in a nested directory.
        artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
                                       self.provenance_capture)

        artifact.save(fp)

        root_dir = str(artifact.uuid)
        expected = {
            'VERSION',
            'checksums.md5',
            'metadata.yaml',
            'data/file1.txt',
            'data/file2.txt',
            'data/nested/file3.txt',
            'data/nested/file4.txt',
            'provenance/metadata.yaml',
            'provenance/VERSION',
            'provenance/citations.bib',
            'provenance/action/action.yaml'
        }

        self.assertArchiveMembers(fp, root_dir, expected)
Example #4
0
    def test_write_v1_archive(self):
        fp = os.path.join(self.temp_dir.name, 'artifact_v1.qza')

        with artifact_version(1):
            artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
                                           self.provenance_capture)
            artifact.save(fp)

        root_dir = str(artifact.uuid)
        expected = {
            'VERSION',
            'metadata.yaml',
            'data/file1.txt',
            'data/file2.txt',
            'data/nested/file3.txt',
            'data/nested/file4.txt',
            'provenance/metadata.yaml',
            'provenance/VERSION',
            'provenance/action/action.yaml',
        }
        self.assertArchiveMembers(fp, root_dir, expected)

        with zipfile.ZipFile(fp, mode='r') as zf:
            version = zf.read(os.path.join(root_dir, 'VERSION'))
        self.assertRegex(str(version), '^.*archive: 1.*$')
    def test_writer_transformer(self):
        # `Artifact._from_view` invokes transformer that handles `dataframe` ->
        # `WinnowedFormat` with all input, because the `WinnowedDirectoryFormat` has
        # been registered as the directory format for the semantic type.
        artifact = Artifact._from_view(Winnowed, [(exp_featureOrdering, exp_auc, exp_permanova)],
                                       list, archive.ImportProvenanceCapture())

        # Test that the directory and file format can be read again.
        got_featureOrdering, got_auc, got_permanova = artifact.view( list )[0]
        pd.testing.assert_frame_equal(
            got_featureOrdering.astype(str),
            exp_featureOrdering.astype(str),
            check_dtype=False
        ) # Avoid checking values since reading df stores as objects while, hard coding in does not
        # ex) bool(False) == Object(False) in pandas is False although the values function the same.
        pd.testing.assert_frame_equal(
            got_auc.astype(str),
            exp_auc.astype(str),
            check_dtype=False
        )
        pd.testing.assert_frame_equal(
            got_permanova.astype(str),
            exp_permanova.astype(str),
            check_dtype=False
        )
Example #6
0
    def test_from_view(self):
        artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
                                       self.provenance_capture)

        self.assertEqual(artifact.type, FourInts)
        # We don't know what the UUID is because it's generated within
        # Artifact._from_view.
        self.assertIsInstance(artifact.uuid, uuid.UUID)
        self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
        # Can produce same view if called again.
        self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
Example #7
0
    def test_from_view(self):
        artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
                                       self.provenance_capture)

        self.assertEqual(artifact.type, FourInts)
        # We don't know what the UUID is because it's generated within
        # Artifact._from_view.
        self.assertIsInstance(artifact.uuid, uuid.UUID)
        self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
        # Can produce same view if called again.
        self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
Example #8
0
 def test_writer_transformer(self):
     # `Artifact._from_view` invokes transformer that handles `dict` ->
     # `MappingFormat`, because the `MappingDirectoryFormat` has
     # been registered as the directory format for the semantic type.
     # We didn't define a `MappingDirectoryFormat` ->
     # `MappingFormat` tranformer because
     # `model.SingleFileDirectoryFormat` handles that transformation for
     # us.
     artifact = Artifact._from_view(Mapping, {'abc': 'cat', 'def': 'dog'},
                                    dict, archive.ImportProvenanceCapture())
     # Test that the directory and file format can be read again.
     self.assertEqual(artifact.view(dict), {'abc': 'cat', 'def': 'dog'})
 def test_writer_transformer(self):
     for type in IntSequence1, IntSequence2:
         # `Artifact._from_view` invokes transformer that handles `list` ->
         # `SingleIntFormat`, because the `SingleIntDirectoryFormat` has
         # been registered as the directory format for the semantic type.
         # We didn't define a `SingleIntDirectoryFormat` ->
         # `SingleIntFormat` tranformer because
         # `model.SingleFileDirectoryFormat` handles that transformation for
         # us.
         artifact = Artifact._from_view(type, [1, 2, 42, -999, 42, 0], list,
                                        archive.ImportProvenanceCapture())
         # Test that the directory and file format can be read again.
         self.assertEqual(artifact.view(list), [1, 2, 42, -999, 42, 0])
 def test_writer_transformer(self):
     for type in IntSequence1, IntSequence2:
         # `Artifact._from_view` invokes transformer that handles `list` ->
         # `SingleIntFormat`, because the `SingleIntDirectoryFormat` has
         # been registered as the directory format for the semantic type.
         # We didn't define a `SingleIntDirectoryFormat` ->
         # `SingleIntFormat` tranformer because
         # `model.SingleFileDirectoryFormat` handles that transformation for
         # us.
         artifact = Artifact._from_view(type, [1, 2, 42, -999, 42, 0], list,
                                        archive.ImportProvenanceCapture())
         # Test that the directory and file format can be read again.
         self.assertEqual(artifact.view(list), [1, 2, 42, -999, 42, 0])
 def test_writer_transformer(self):
     # `Artifact._from_view` invokes transformer that handles `dict` ->
     # `MappingFormat`, because the `MappingDirectoryFormat` has
     # been registered as the directory format for the semantic type.
     # We didn't define a `MappingDirectoryFormat` ->
     # `MappingFormat` tranformer because
     # `model.SingleFileDirectoryFormat` handles that transformation for
     # us.
     artifact = Artifact._from_view(Mapping, {
         'abc': 'cat',
         'def': 'dog'
     }, dict, archive.ImportProvenanceCapture())
     # Test that the directory and file format can be read again.
     self.assertEqual(artifact.view(dict), {'abc': 'cat', 'def': 'dog'})
Example #12
0
    def test_from_view_different_type_with_multiple_view_types(self):
        artifact = Artifact._from_view(IntSequence1, [42, 42, 43, -999, 42],
                                       list, self.provenance_capture)

        self.assertEqual(artifact.type, IntSequence1)
        self.assertIsInstance(artifact.uuid, uuid.UUID)

        self.assertEqual(artifact.view(list),
                         [42, 42, 43, -999, 42])
        self.assertEqual(artifact.view(list),
                         [42, 42, 43, -999, 42])

        self.assertEqual(artifact.view(collections.Counter),
                         collections.Counter({42: 3, 43: 1, -999: 1}))
        self.assertEqual(artifact.view(collections.Counter),
                         collections.Counter({42: 3, 43: 1, -999: 1}))
Example #13
0
    def test_from_view_different_type_with_multiple_view_types(self):
        artifact = Artifact._from_view(IntSequence1, [42, 42, 43, -999, 42],
                                       list, self.provenance_capture)

        self.assertEqual(artifact.type, IntSequence1)
        self.assertIsInstance(artifact.uuid, uuid.UUID)

        self.assertEqual(artifact.view(list),
                         [42, 42, 43, -999, 42])
        self.assertEqual(artifact.view(list),
                         [42, 42, 43, -999, 42])

        self.assertEqual(artifact.view(collections.Counter),
                         collections.Counter({42: 3, 43: 1, -999: 1}))
        self.assertEqual(artifact.view(collections.Counter),
                         collections.Counter({42: 3, 43: 1, -999: 1}))