Skip to content
4 changes: 2 additions & 2 deletions src/rachis/core/archive/tests/test_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_import(self):
obs = list(map(lambda item: (item[0], item[1].fields['title']),
archiver.citations.items()))

self.assertEqual(obs, expected)
self.assertEqual(sorted(obs), sorted(expected))

with (archiver.provenance_dir / 'action' / 'action.yaml').open() as fh:
action_yaml = fh.read()
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_action(self):
obs = list(map(lambda item: (item[0], item[1].fields['title']),
archiver.citations.items()))

self.assertEqual(obs, expected)
self.assertEqual(sorted(obs), sorted(expected))

with (archiver.provenance_dir / 'action' / 'action.yaml').open() as fh:
action_yaml = fh.read()
Expand Down
25 changes: 25 additions & 0 deletions src/rachis/core/testing/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,28 @@ class ExportableOnlyFormat(TextFileFormat):
"""
A format that can only be transformed to.
"""

class FirstStepFormat(model.DirectoryFormat):
"""
A format for testing transitive transformers
"""

class SecondStepFormat(model.DirectoryFormat):
"""
A format for testing transitive transformers
"""

class ThirdStepFormat(model.DirectoryFormat):
"""
A format for testing transitive transformers
"""

class FourthStepFormat(model.DirectoryFormat):
"""
A format for testing transitive transformers
"""

class FifthStepFormat(model.DirectoryFormat):
"""
A format for testing transitive transformers
"""
45 changes: 42 additions & 3 deletions src/rachis/core/testing/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@
Cephalapod,
CephalapodDirectoryFormat,
ImportableOnlyFormat,
ExportableOnlyFormat
ExportableOnlyFormat,
FirstStepFormat,
SecondStepFormat,
ThirdStepFormat,
FourthStepFormat,
FifthStepFormat,
)

from .type import (IntSequence1, IntSequence2, IntSequence3, Mapping, FourInts,
SingleInt, Kennel, Dog, Cat, C1, C2, C3, Foo, Bar, Baz,
AscIntSequence, Squid, Octopus, Cuttlefish)
AscIntSequence, Squid, Octopus, Cuttlefish, FirstStep,
SecondStep, ThirdStep, FourthStep, FifthStep)
from .method import (concatenate_ints, split_ints, merge_mappings,
identity_with_metadata, identity_with_metadata_column,
identity_with_categorical_metadata_column,
Expand Down Expand Up @@ -120,7 +126,9 @@
IntSequenceFormatV2, MappingFormat, IntSequenceV2DirectoryFormat,
IntSequenceMultiFileDirectoryFormat, MappingDirectoryFormat,
EchoDirectoryFormat, EchoFormat, Cephalapod, CephalapodDirectoryFormat,
ImportableOnlyFormat, ExportableOnlyFormat)
ImportableOnlyFormat, ExportableOnlyFormat, FirstStepFormat,
SecondStepFormat, ThirdStepFormat, FourthStepFormat, FifthStepFormat,
)

dummy_plugin.register_formats(
FourIntsDirectoryFormat, UnimportableDirectoryFormat, UnimportableFormat,
Expand Down Expand Up @@ -182,6 +190,37 @@ def factory():
description="The second IntSequence",
examples={'IntSequence2 import example': is2_use}
)

dummy_plugin.register_artifact_class(
FirstStep,
directory_format=FirstStepFormat,
description="First step"
)

dummy_plugin.register_artifact_class(
SecondStep,
directory_format=SecondStepFormat,
description="Second step"
)

dummy_plugin.register_artifact_class(
ThirdStep,
directory_format=ThirdStepFormat,
description="Third step"
)

dummy_plugin.register_artifact_class(
FourthStep,
directory_format=FourthStepFormat,
description="Fourth step"
)

dummy_plugin.register_artifact_class(
FifthStep,
directory_format=FifthStepFormat,
description="Fifth step"
)

dummy_plugin.register_semantic_type_to_format(
IntSequence3,
directory_format=IntSequenceMultiFileDirectoryFormat
Expand Down
31 changes: 30 additions & 1 deletion src/rachis/core/testing/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
RedundantSingleIntDirectoryFormat,
EchoFormat,
ImportableOnlyFormat,
ExportableOnlyFormat
ExportableOnlyFormat,
FirstStepFormat,
SecondStepFormat,
ThirdStepFormat,
FourthStepFormat,
FifthStepFormat,
)
from .plugin import dummy_plugin, citations

Expand Down Expand Up @@ -206,3 +211,27 @@ def _4242(data: ImportableOnlyFormat) -> IntSequenceDirectoryFormat:
@dummy_plugin.register_transformer()
def _4243(data: IntSequenceDirectoryFormat) -> ExportableOnlyFormat:
return ExportableOnlyFormat()


# only for testing transitive transformers
@dummy_plugin.register_transformer(upgrade=True)
def _6000(data: FirstStepFormat) -> SecondStepFormat:
return SecondStepFormat()


# only for testing transitive transformers
@dummy_plugin.register_transformer(upgrade=True)
def _6001(data: SecondStepFormat) -> ThirdStepFormat:
return ThirdStepFormat()


# only for testing transitive transformers
@dummy_plugin.register_transformer
def _6002(data: ThirdStepFormat) -> FourthStepFormat:
return FourthStepFormat()


# only for testing transitive transformers
@dummy_plugin.register_transformer(upgrade=False)
def _6003(data: ThirdStepFormat) -> FifthStepFormat:
return FifthStepFormat()
6 changes: 6 additions & 0 deletions src/rachis/core/testing/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@
Squid = plugin.SemanticType('Squid')
Octopus = plugin.SemanticType('Octopus')
Cuttlefish = plugin.SemanticType('Cuttlefish')

FirstStep = plugin.SemanticType('FirstStep')
SecondStep = plugin.SemanticType('SecondStep')
ThirdStep = plugin.SemanticType('ThirdStep')
FourthStep = plugin.SemanticType('FourthStep')
FifthStep = plugin.SemanticType('FifthStep')
60 changes: 60 additions & 0 deletions src/rachis/core/tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import unittest
from typing import Union
from tempfile import TemporaryDirectory

from rachis import Artifact
from rachis.core.testing.format import (
ThirdStepFormat, FourthStepFormat, FifthStepFormat, Cephalapod)


class TestTransitiveTransfomrers(unittest.TestCase):
@classmethod
def setUpClass(cls):
with TemporaryDirectory() as tempdir:
cls.first_format = Artifact.import_data(
type='FirstStep', view=tempdir
)

cls.int_sequence = Artifact.import_data(
type='IntSequence1', view=[1, 2, 3]
)

def test_first_to_third(self):
"""
Path exists and is upgraded.
FirstStepFormat -> SecondStepFormat -> ThirdStepFormat
"""
view = self.first_format.view(ThirdStepFormat)
self.assertEqual(type(view), ThirdStepFormat)

def test_first_to_fourth_fails(self):
"""
Path exists but is not upgraded.
FirstStepFormat -> SecondStepFormat -> ThirdStepFormat -None-> Fourth
"""
with self.assertRaisesRegex(Exception, 'No transformation from'):
self.first_format.view(FourthStepFormat)

def test_union_transitivity(self):
"""
Path exists between FirstStepFormat and ThirdStepFormat but not between
FirsStepFormat and Cephalapod.
"""
view = self.first_format.view(Union[Cephalapod, ThirdStepFormat])
self.assertEqual(type(view), ThirdStepFormat)

def test_int_sequence_dir_to_list(self):
"""
Tests that unwrapping a format and then transforming does not require
upgrading the path.
"""
view = self.int_sequence.view(list)
self.assertEqual(type(view), list)

def test_lossy_transformer(self):
"""
Tests that path with lossy steps still completes.
First -> Second -> Third -lossy-> Fifth
"""
view = self.first_format.view(FifthStepFormat)
self.assertEqual(type(view), FifthStepFormat)
Loading
Loading