Commit ffd8158e authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][asset] Remove data duplication

parent ecfedf2f
......@@ -53,6 +53,20 @@ def unforkable_asset_type(request):
return request.param
existing_asset_name_map = {
AssetType.ALGORITHM: "autonomous/add/1",
AssetType.DATABASE: "simple/1",
AssetType.DATAFORMAT: "user/complexes/1",
AssetType.EXPERIMENT: "user/user/double/1/double",
AssetType.LIBRARY: "user/sum/1",
AssetType.PLOTTER: "user/scatter/1",
AssetType.PLOTTERPARAMETER: "plot/config/1",
AssetType.PROTOCOLTEMPLATE: "double/1",
AssetType.TOOLCHAIN: "user/double/1",
AssetType.UNKNOWN: None,
}
class TestAssetType:
"""Test the asset type enum"""
......@@ -69,19 +83,6 @@ class TestAssetType:
AssetType.UNKNOWN: None,
}
existing_asset_name_map = {
AssetType.ALGORITHM: "autonomous/add/1",
AssetType.DATABASE: "simple/1",
AssetType.DATAFORMAT: "user/complexes/1",
AssetType.EXPERIMENT: "user/user/double/1/double",
AssetType.LIBRARY: "user/sum/1",
AssetType.PLOTTER: "user/scatter/1",
AssetType.PLOTTERPARAMETER: "plot/config/1",
AssetType.PROTOCOLTEMPLATE: "double/1",
AssetType.TOOLCHAIN: "user/double/1",
AssetType.UNKNOWN: None,
}
def test_unknown_validation(self):
with pytest.raises(RuntimeError):
AssetType.UNKNOWN.validate({})
......@@ -113,17 +114,17 @@ class TestAssetType:
uncreatable_asset_type.create_new(test_prefix, asset_name)
def test_create_new_version(self, test_prefix, creatable_asset_type):
asset_name = self.existing_asset_name_map[creatable_asset_type]
asset_name = existing_asset_name_map[creatable_asset_type]
result = creatable_asset_type.create_new_version(test_prefix, asset_name)
assert result
def test_create_new_version_failure(self, test_prefix, uncreatable_asset_type):
asset_name = self.existing_asset_name_map[uncreatable_asset_type]
asset_name = existing_asset_name_map[uncreatable_asset_type]
with pytest.raises(RuntimeError):
uncreatable_asset_type.create_new_version(test_prefix, asset_name)
def test_fork(self, test_prefix, forkable_asset_type):
source_asset_name = self.existing_asset_name_map[forkable_asset_type]
source_asset_name = existing_asset_name_map[forkable_asset_type]
dest_asset_name = self.asset_name_map[forkable_asset_type]
result = forkable_asset_type.fork(
test_prefix, source_asset_name, dest_asset_name
......@@ -131,7 +132,7 @@ class TestAssetType:
assert result
def test_fork_failure(self, test_prefix, unforkable_asset_type):
source_asset_name = self.existing_asset_name_map[unforkable_asset_type]
source_asset_name = existing_asset_name_map[unforkable_asset_type]
dest_asset_name = self.asset_name_map[unforkable_asset_type]
with pytest.raises(RuntimeError):
unforkable_asset_type.fork(test_prefix, source_asset_name, dest_asset_name)
......@@ -140,7 +141,7 @@ class TestAssetType:
with tempfile.TemporaryDirectory(suffix=".prefix") as prefix:
tmp_prefix = os.path.join(prefix, "prefix")
shutil.copytree(test_prefix, tmp_prefix)
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
result = asset_type.delete(tmp_prefix, asset_name)
assert result
......@@ -148,21 +149,8 @@ class TestAssetType:
class TestAsset:
"""Test that the asset works correctly"""
existing_asset_name_map = {
AssetType.ALGORITHM: "autonomous/add/1",
AssetType.DATABASE: "simple/1",
AssetType.DATAFORMAT: "user/complexes/1",
AssetType.EXPERIMENT: "user/user/double/1/double",
AssetType.LIBRARY: "user/sum/1",
AssetType.PLOTTER: "user/scatter/1",
AssetType.PLOTTERPARAMETER: "plot/config/1",
AssetType.PROTOCOLTEMPLATE: "double/1",
AssetType.TOOLCHAIN: "user/double/1",
AssetType.UNKNOWN: None,
}
def test_from_path(self, test_prefix, asset_type):
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
full_path = os.path.join(test_prefix, asset_type.path, asset_name)
asset = Asset.from_path(test_prefix, full_path)
assert asset.prefix == test_prefix
......@@ -170,17 +158,17 @@ class TestAsset:
assert asset.name == asset_name
def test_declaration_path(self, test_prefix, asset_type):
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
assert os.path.exists(asset.declaration_path)
def test_documentation_path(self, test_prefix, asset_type):
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
assert os.path.exists(asset.documentation_path)
def test_code_path(self, test_prefix, asset_type):
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
if asset_type.has_code():
assert os.path.exists(asset.code_path)
......@@ -191,13 +179,13 @@ class TestAsset:
with tempfile.TemporaryDirectory(suffix=".prefix") as prefix:
tmp_prefix = os.path.join(prefix, "prefix")
shutil.copytree(test_prefix, tmp_prefix)
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
asset = Asset(tmp_prefix, asset_type, asset_name)
result = asset.delete()
assert result
def test_declaration_property(self, test_prefix, asset_type):
asset_name = self.existing_asset_name_map[asset_type]
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
declaration = asset.declaration
with open(asset.declaration_path, "rt") as json_file:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment