diff --git a/tests/base.py b/tests/base.py index d0f8b1e..8018d49 100644 --- a/tests/base.py +++ b/tests/base.py @@ -8,5 +8,5 @@ class BaseTestCase(unittest.TestCase): """ def setUp(self): - self.path = str(os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "")) + self.path = os.path.join(os.path.dirname(__file__), "data") super().setUp() diff --git a/tests/data/children/extra_key.json b/tests/data/children/extra_key.json deleted file mode 100644 index 1a14448..0000000 --- a/tests/data/children/extra_key.json +++ /dev/null @@ -1,13 +0,0 @@ -[ - { - "key": "gis", - "id": "some-id", - "uri_env_name": "SOME_ENV_VAR_NAME", - "some_extra_key": "should not be a problem if present" - }, - { - "key": "some_weird_other_child", - "id": "some-other-id", - "uri_env_name": "SOME_ENV_VAR_NAME" - } -] diff --git a/tests/data/children/extra_property.json b/tests/data/children/extra_property.json deleted file mode 100644 index 83afc66..0000000 --- a/tests/data/children/extra_property.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - { - "key": "gis", - "id": "some-id", - "uri_env_name": "SOME_ENV_VAR_NAME", - "some_extra_property": "should not be a problem if present" - } -] diff --git a/tests/data/children/invalid_env_name.json b/tests/data/children/invalid_env_name.json deleted file mode 100644 index 69391f9..0000000 --- a/tests/data/children/invalid_env_name.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "key": "gis", - "id": "some-id", - "uri_env_name": "an environment variable which isnt in CAPS_CASE is invalid per the credentials spec" - } -] diff --git a/tests/data/children/valid.json b/tests/data/children/valid.json deleted file mode 100644 index 37fed88..0000000 --- a/tests/data/children/valid.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "key": "gis", - "id": "some-id", - "uri_env_name": "NAME_OF_SOME_ENV_VAR_THAT_CONTAINS_A_URI" - } -] diff --git a/tests/data/twines/invalid_children_dict_not_array_twine.json b/tests/data/twines/invalid_children_dict_not_array_twine.json deleted file mode 100644 index 66245b2..0000000 --- a/tests/data/twines/invalid_children_dict_not_array_twine.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "children": {} -} diff --git a/tests/data/twines/invalid_children_no_key_twine.json b/tests/data/twines/invalid_children_no_key_twine.json deleted file mode 100644 index 1515fd3..0000000 --- a/tests/data/twines/invalid_children_no_key_twine.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "children": [ - { - "purpose": "Something to do with GIS data.", - "notes": "This filter (which can use the extremely powerful 'lucene' query syntax)\n allows the digital twin to locate other digital twins (public across octue or\n private in your workspace) which can provide the data you need.", - "filters": "tags:gis" - } - ] -} diff --git a/tests/data/twines/valid_children_twine.json b/tests/data/twines/valid_children_twine.json deleted file mode 100644 index 2293ec6..0000000 --- a/tests/data/twines/valid_children_twine.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "children": [ - { - "key": "gis", - "purpose": "Something to do with GIS data.", - "notes": "Some internal note about how the filters work or similar.", - "filters": "tags:gis" - } - ] -} diff --git a/tests/data/twines/valid_empty_children_twine.json b/tests/data/twines/valid_empty_children_twine.json deleted file mode 100644 index 266797e..0000000 --- a/tests/data/twines/valid_empty_children_twine.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "children": [ - ] -} diff --git a/tests/test_children.py b/tests/test_children.py index ba5d698..a8e7930 100644 --- a/tests/test_children.py +++ b/tests/test_children.py @@ -13,92 +13,132 @@ def test_invalid_children_dict_not_array(self): """ Ensures InvalidTwine exceptions are raised when instantiating twines where `children` entry is incorrectly specified as a dict, not an array """ - twine_file = self.path + "twines/invalid_children_dict_not_array_twine.json" with self.assertRaises(exceptions.InvalidTwine): - Twine(source=twine_file) + Twine(source="""{"children": {}}""") def test_invalid_children_no_key(self): """ Ensures InvalidTwine exceptions are raised when instantiating twines where a child is specified without the required `key` field """ - twine_file = self.path + "twines/invalid_children_no_key_twine.json" + source = """ + { + "children": [{"purpose": "The purpose.", "notes": "Here are some notes.", "filters": "tags:gis"}] + } + """ + with self.assertRaises(exceptions.InvalidTwine): - Twine(source=twine_file) + Twine(source=source) def test_valid_children(self): - """ Ensures that a twine can be instantiated with correctly specified children + """ Ensures that a twine with one child can be instantiated correctly. """ - twine_file = self.path + "twines/valid_children_twine.json" - twine = Twine(source=twine_file) - self.assertEqual(len(twine._children), 1) + source = """ + { + "children": [{"key": "gis", "purpose": "The purpose.", "notes": "Some notes.", "filters": "tags:gis"}] + } + """ + self.assertEqual(len(Twine(source=source)._raw["children"]), 1) def test_empty_children(self): """ Ensures that a twine file will validate with an empty list object as children """ - twine_file = self.path + "twines/valid_empty_children_twine.json" - twine = Twine(source=twine_file) - self.assertEqual(len(twine._children), 0) + twine = Twine(source="""{"children": []}""") + self.assertEqual(len(twine._raw["children"]), 0) class TestChildrenValidation(BaseTestCase): """ Tests related to whether validation of children occurs successfully (given a valid twine) """ + VALID_TWINE_WITH_CHILDREN = """ + { + "children": [{"key": "gis", "purpose": "The purpose", "notes": "Some notes.", "filters": "tags:gis"}] + } + """ + + VALID_CHILD_VALUE = """ + [ + {"key": "gis", "id": "some-id", "uri_env_name": "NAME_OF_SOME_ENV_VAR_THAT_CONTAINS_A_URI"} + ] + """ + def test_no_children(self): """ Test that a twine with no children will validate on an empty children input """ - twine = Twine() # Creates empty twine - twine.validate_children(source="[]") + Twine().validate_children(source=[]) def test_missing_children(self): """ Test that a twine with children will not validate on an empty children input """ - twine = Twine(source=self.path + "twines/valid_children_twine.json") with self.assertRaises(exceptions.InvalidValuesContents): - twine.validate_children(source="[]") + Twine(source=self.VALID_TWINE_WITH_CHILDREN).validate_children(source=[]) def test_extra_children(self): """ Test that a twine with no children will not validate a non-empty children input """ - twine = Twine() # Creates empty twine with self.assertRaises(exceptions.InvalidValuesContents): - twine.validate_children(source=self.path + "children/valid.json") + Twine().validate_children(source=self.VALID_CHILD_VALUE) - def test_extra_key(self): - """ Test that children with extra data will not raise validation error + def test_extra_key_validation_on_empty_twine(self): + """ Test that children with extra data will not raise a validation error on an empty twine. """ - twine = Twine() # Creates empty twine + children_values_with_extra_data = """ + [ + {"key": "gis", "id": "id", "uri_env_name": "VAR_NAME", "an_extra_key": "not a problem if present"}, + {"key": "some_weird_other_child", "id": "some-other-id", "uri_env_name": "SOME_ENV_VAR_NAME"} + ] + """ + with self.assertRaises(exceptions.InvalidValuesContents): - twine.validate_children(source=self.path + "children/extra_key.json") + Twine().validate_children(source=children_values_with_extra_data) - def test_extra_property(self): - """ Test that children with extra data will not raise validation error + def test_extra_key_validation_on_valid_twine(self): + """ Test that children with extra data will not raise a validation error on a non-empty valid twine. # TODO review this behaviour - possibly should raise an error but allow for a user specified extra_data property """ - twine = Twine(source=self.path + "twines/valid_children_twine.json") - twine.validate_children(source=self.path + "children/extra_property.json") + single_child_with_extra_data = """ + [ + { + "key": "gis", + "id": "some-id", + "uri_env_name": "SOME_ENV_VAR_NAME", + "some_extra_property": "should not be a problem if present" + } + ] + """ + + twine = Twine(source=self.VALID_TWINE_WITH_CHILDREN) + twine.validate_children(source=single_child_with_extra_data) def test_invalid_env_name(self): """ Test that a child uri env name not in ALL_CAPS_SNAKE_CASE doesn't validate """ - twine = Twine() # Creates empty twine + child_with_invalid_environment_variable_name = """ + [ + { + "key": "gis", + "id": "some-id", + "uri_env_name": "an environment variable not in CAPS_CASE is invalid per the credentials spec" + } + ] + """ + with self.assertRaises(exceptions.InvalidValuesContents): - twine.validate_children(source=self.path + "children/invalid_env_name.json") + Twine().validate_children(source=child_with_invalid_environment_variable_name) def test_invalid_json(self): """ Tests that a children entry with invalid json will raise an error """ - twine = Twine(source=self.path + "twines/valid_children_twine.json") with self.assertRaises(exceptions.InvalidValuesJson): - twine.validate_children(source="[") + Twine(source=self.VALID_TWINE_WITH_CHILDREN).validate_children(source="[") def test_valid(self): """ Test that a valid twine will validate valid children Valiantly and Validly validating validity since 1983. To those reading this, know that YOU'RE valid. """ - twine = Twine(source=self.path + "twines/valid_children_twine.json") - twine.validate_children(source=self.path + "children/valid.json") + twine = Twine(source=self.VALID_TWINE_WITH_CHILDREN) + twine.validate_children(source=self.VALID_CHILD_VALUE) if __name__ == "__main__": diff --git a/tests/test_credentials.py b/tests/test_credentials.py index cbfc8b2..e7bb4f3 100644 --- a/tests/test_credentials.py +++ b/tests/test_credentials.py @@ -15,7 +15,7 @@ def test_fails_on_no_name(self): """ Ensures InvalidTwine exceptions are raised when instantiating twines with a missing `name` field in a credential """ - twine_file = self.path + "twines/invalid_credentials_no_name_twine.json" + twine_file = os.path.join(self.path, "twines", "invalid_credentials_no_name_twine.json") with self.assertRaises(exceptions.InvalidTwine): Twine(source=twine_file) @@ -23,7 +23,7 @@ def test_fails_on_lowercase_name(self): """ Ensures InvalidTwine exceptions are raised when instantiating twines with lowercase letters in the `name` field """ - twine_file = self.path + "twines/invalid_credentials_lowercase_name_twine.json" + twine_file = os.path.join(self.path, "twines", "invalid_credentials_lowercase_name_twine.json") with self.assertRaises(exceptions.InvalidTwine): Twine(source=twine_file) @@ -31,12 +31,12 @@ def test_fails_on_dict(self): """ Ensures InvalidTwine exceptions are raised when instantiating twines with invalid `credentials` entries (given as a dict, not an array) """ - twine_file = self.path + "twines/invalid_credentials_dict_not_array_twine.json" + twine_file = os.path.join(self.path, "twines", "invalid_credentials_dict_not_array_twine.json") with self.assertRaises(exceptions.InvalidTwine): Twine(source=twine_file) def test_fails_on_name_whitespace(self): - twine_file = self.path + "twines/invalid_credentials_space_in_name_twine.json" + twine_file = os.path.join(self.path, "twines", "invalid_credentials_space_in_name_twine.json") with self.assertRaises(exceptions.InvalidTwine): Twine(source=twine_file) @@ -48,20 +48,20 @@ class TestCredentialsValidation(BaseTestCase): def test_no_credentials(self): """ Test that a twine with no credentials will validate straightforwardly """ - twine = Twine(source=self.path + "twines/valid_schema_twine.json") + twine = Twine(source=os.path.join(self.path, "twines", "valid_schema_twine.json")) twine.validate_credentials() def test_missing_credentials(self): """ Test that a twine with credentials will not validate where they are missing from the environment """ - twine = Twine(source=self.path + "twines/valid_credentials_twine.json") + twine = Twine(source=os.path.join(self.path, "twines", "valid_credentials_twine.json")) with self.assertRaises(exceptions.CredentialNotFound): twine.validate_credentials() def test_default_credentials(self): """ Test that a twine with credentials will validate where ones with defaults are missing from the environment """ - twine = Twine(source=self.path + "twines/valid_credentials_twine.json") + twine = Twine(source=os.path.join(self.path, "twines", "valid_credentials_twine.json")) with mock.patch.dict(os.environ, {"SECRET_THE_FIRST": "a value", "SECRET_THE_SECOND": "another value"}): credentials = twine.validate_credentials() @@ -73,7 +73,7 @@ def test_default_credentials(self): def test_nondefault_credentials(self): """ Test that the environment will override a default value for a credential """ - twine = Twine(source=self.path + "twines/valid_credentials_twine.json") + twine = Twine(source=os.path.join(self.path, "twines", "valid_credentials_twine.json")) with mock.patch.dict( os.environ, {"SECRET_THE_FIRST": "a value", "SECRET_THE_SECOND": "another value", "SECRET_THE_THIRD": "nondefault"}, diff --git a/tests/test_manifest_strands.py b/tests/test_manifest_strands.py index dca2962..23f5a67 100644 --- a/tests/test_manifest_strands.py +++ b/tests/test_manifest_strands.py @@ -1,3 +1,4 @@ +import os import unittest from twined import Twine, exceptions @@ -11,9 +12,9 @@ class TestManifestStrands(BaseTestCase): def test_missing_manifest_files(self): """ Ensures that if you try to read values from missing files, the right exceptions get raised """ - twine_file = self.path + "twines/valid_manifest_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_manifest_twine.json") twine = Twine(source=twine_file) - file = self.path + "not_a_file.json" + file = os.path.join(self.path, "not_a_file.json") with self.assertRaises(exceptions.ConfigurationManifestFileNotFound): twine.validate_configuration_manifest(source=file) @@ -26,65 +27,65 @@ def test_missing_manifest_files(self): def test_valid_manifest_files(self): """ Ensures that a manifest file will validate """ - twine_file = self.path + "twines/valid_manifest_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_manifest_twine.json") twine = Twine(source=twine_file) - file = self.path + "manifests/configuration/configuration_valid.json" + file = os.path.join(self.path, "manifests", "configuration", "configuration_valid.json") twine.validate_input_manifest(source=file) - file = self.path + "manifests/inputs/input_valid.json" + file = os.path.join(self.path, "manifests", "inputs", "input_valid.json") twine.validate_input_manifest(source=file) - file = self.path + "manifests/outputs/output_valid.json" + file = os.path.join(self.path, "manifests", "outputs", "output_valid.json") twine.validate_output_manifest(source=file) # def test_empty_values(self): # """ Ensures that appropriate errors are generated for invalid values # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # values_file = self.path + "configurations/empty.json" + # values_file = os.path.join(self.path, "configurations", "empty.json") # with self.assertRaises(exceptions.InvalidValuesJson): # twine.validate_configuration(file=values_file) # # def test_incorrect_values(self): # """ Ensures that appropriate errors are generated for invalid values # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # values_file = self.path + "configurations/incorrect.json" + # values_file = os.path.join(self.path, "configurations", "incorrect.json") # with self.assertRaises(exceptions.InvalidValuesContents): # twine.validate_configuration(file=values_file) # # def test_missing_not_required_values(self): # """ Ensures that appropriate errors are generated for missing values # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # values_file = self.path + "outputs/missing_not_required.json" + # values_file = os.path.join(self.path, "outputs", "missing_not_required.json") # twine.validate_output_values(file=values_file) # # def test_missing_required_values(self): # """ Ensures that appropriate errors are generated for missing values # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # values_file = self.path + "inputs/missing_required.json" + # values_file = os.path.join(self.path, "inputs", "missing_required.json") # with self.assertRaises(exceptions.InvalidValuesContents): # twine.validate_input_values(file=values_file) # # def test_valid_values_files(self): # """ Ensures that values can be read and validated correctly from files on disk # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # twine.validate_configuration(file=self.path + "configurations/valid.json") - # twine.validate_input_values(file=self.path + "inputs/valid.json") - # twine.validate_output_values(file=self.path + "outputs/valid.json") + # twine.validate_configuration(file=os.path.join(self.path, "configurations", "valid.json")) + # twine.validate_input_values(file=os.path.join(self.path, "inputs", "valid.json")) + # twine.validate_output_values(file=os.path.join(self.path, "outputs", "valid.json")) # # def test_valid_values_json(self): # """ Ensures that values can be read and validated correctly from a json string # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # values_file = self.path + "configurations/valid.json" + # values_file = os.path.join(self.path, "configurations", "valid.json") # with open(values_file, "r", encoding="utf-8") as f: # json_string = f.read() # twine.validate_configuration(json=json_string) @@ -92,9 +93,9 @@ def test_valid_manifest_files(self): # def test_valid_with_extra_values(self): # """ Ensures that extra values get ignored # """ - # twine_file = self.path + "twines/valid_schema_twine.json" + # twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") # twine = Twine(file=twine_file) - # values_file = self.path + "configurations/valid_with_extra.json" + # values_file = os.path.join(self.path, "configurations", "valid_with_extra.json") # twine.validate_configuration(file=values_file) diff --git a/tests/test_schema_strands.py b/tests/test_schema_strands.py index 4970d3d..31bb90d 100644 --- a/tests/test_schema_strands.py +++ b/tests/test_schema_strands.py @@ -1,3 +1,4 @@ +import os import unittest from twined import Twine, exceptions @@ -13,9 +14,9 @@ def test_invalid_strand(self): Note: This tests an internal method. The current API doesn't allow this error to emerge but tthis check allows us to extend to a generic method """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/configurations/configuration_valid.json" + values_file = os.path.join(self.path, "values", "configurations", "configuration_valid.json") data = twine._load_json("configuration", source=values_file) with self.assertRaises(exceptions.UnknownStrand): twine._validate_against_schema("not_a_strand_name", data) @@ -23,9 +24,9 @@ def test_invalid_strand(self): def test_missing_values_files(self): """ Ensures that if you try to read values from missing files, the right exceptions get raised """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "not_a_file.json" + values_file = os.path.join(self.path, "not_a_file.json") with self.assertRaises(exceptions.ConfigurationValuesFileNotFound): twine.validate_configuration_values(source=values_file) @@ -38,7 +39,7 @@ def test_missing_values_files(self): def test_no_values(self): """ Ensures that giving no data source raises an invalidJson error """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) with self.assertRaises(exceptions.InvalidValuesJson): twine.validate_configuration_values(source=None) @@ -46,16 +47,16 @@ def test_no_values(self): def test_empty_values(self): """ Ensures that appropriate errors are generated for invalid values """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/configurations/configuration_empty.json" + values_file = os.path.join(self.path, "values", "configurations", "configuration_empty.json") with self.assertRaises(exceptions.InvalidValuesJson): twine.validate_configuration_values(source=values_file) def test_strand_not_found(self): """ Ensures that if a twine doesn't have a strand, you can't validate against it """ - twine_file = self.path + "twines/valid_no_output_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_no_output_schema_twine.json") twine = Twine(source=twine_file) with self.assertRaises(exceptions.StrandNotFound): twine.validate_output_values(source="{}") @@ -63,44 +64,44 @@ def test_strand_not_found(self): def test_incorrect_values(self): """ Ensures that appropriate errors are generated for invalid values """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/configurations/configuration_incorrect.json" + values_file = os.path.join(self.path, "values", "configurations", "configuration_incorrect.json") with self.assertRaises(exceptions.InvalidValuesContents): twine.validate_configuration_values(source=values_file) def test_missing_not_required_values(self): """ Ensures that appropriate errors are generated for missing values """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/outputs/output_missing_not_required.json" + values_file = os.path.join(self.path, "values", "outputs", "output_missing_not_required.json") twine.validate_output_values(source=values_file) def test_missing_required_values(self): """ Ensures that appropriate errors are generated for missing values """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/inputs/input_missing_required.json" + values_file = os.path.join(self.path, "values", "inputs", "input_missing_required.json") with self.assertRaises(exceptions.InvalidValuesContents): twine.validate_input_values(source=values_file) def test_valid_values_files(self): """ Ensures that values can be read and validated correctly from files on disk """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - twine.validate_configuration_values(source=self.path + "values/configurations/configuration_valid.json") - twine.validate_input_values(source=self.path + "values/inputs/input_valid.json") - twine.validate_output_values(source=self.path + "values/outputs/output_valid.json") + twine.validate_configuration_values(source=os.path.join(self.path, "values", "configurations", "configuration_valid.json")) + twine.validate_input_values(source=os.path.join(self.path, "values", "inputs", "input_valid.json")) + twine.validate_output_values(source=os.path.join(self.path, "values", "outputs", "output_valid.json")) def test_valid_values_json(self): """ Ensures that values can be read and validated correctly from a json string """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/configurations/configuration_valid.json" + values_file = os.path.join(self.path, "values", "configurations", "configuration_valid.json") with open(values_file, "r", encoding="utf-8") as f: json_string = f.read() twine.validate_configuration_values(source=json_string) @@ -108,9 +109,9 @@ def test_valid_values_json(self): def test_valid_with_extra_values(self): """ Ensures that extra values get ignored """ - twine_file = self.path + "twines/valid_schema_twine.json" + twine_file = os.path.join(self.path, "twines", "valid_schema_twine.json") twine = Twine(source=twine_file) - values_file = self.path + "values/configurations/configuration_valid_with_extra.json" + values_file = os.path.join(self.path, "values", "configurations", "configuration_valid_with_extra.json") twine.validate_configuration_values(source=values_file) diff --git a/tests/test_twine.py b/tests/test_twine.py index 1f5fb2f..6264f05 100644 --- a/tests/test_twine.py +++ b/tests/test_twine.py @@ -1,3 +1,4 @@ +import os import unittest from twined import Twine, exceptions @@ -6,20 +7,18 @@ class TestTwine(BaseTestCase): """ Testing operation of the Twine class - """ + """ def test_init_twine_with_filename(self): """ Ensures that the twine class can be instantiated with a file """ - twine_file = self.path + "apps/simple_app/twine.json" - Twine(source=twine_file) + Twine(source=os.path.join(self.path, "apps", "simple_app", "twine.json")) def test_init_twine_with_json(self): """ Ensures that a twine can be instantiated with a json string """ - with open(self.path + "apps/simple_app/twine.json", "r", encoding="utf-8") as f: - json_string = f.read() - Twine(source=json_string) + with open(os.path.join(self.path, "apps", "simple_app", "twine.json"), "r", encoding="utf-8") as f: + Twine(source=f.read()) def test_no_twine(self): """ Tests that the canonical-but-useless case of no twine provided validates empty @@ -29,9 +28,8 @@ def test_no_twine(self): def test_incorrect_version_twine(self): """ Ensures exception is thrown on mismatch between installed and specified versions of twined """ - twine_file = self.path + "twines/incorrect_version_twine.json" with self.assertRaises(exceptions.TwineVersionConflict): - Twine(source=twine_file) + Twine(source=os.path.join(self.path, "twines", "incorrect_version_twine.json")) def test_empty_twine(self): """ Ensures that an empty twine file can be loaded @@ -46,21 +44,18 @@ def test_empty_twine(self): def test_example_twine(self): """ Ensures that the example (full) twine can be loaded and validated """ - twine_file = self.path + "apps/example_app/twine.json" - Twine(source=twine_file) + Twine(source=os.path.join(self.path, "apps", "example_app", "twine.json")) def test_simple_twine(self): """ Ensures that the simple app schema can be loaded and used to parse some basic config and values data """ - twine_file = self.path + "apps/simple_app/twine.json" - Twine(source=twine_file) + Twine(source=os.path.join(self.path, "apps", "simple_app", "twine.json")) def test_broken_json_twine(self): """ Ensures that an invalid json file raises an InvalidTwine exception """ - twine_file = self.path + "twines/invalid_json_twine.json" with self.assertRaises(exceptions.InvalidTwineJson): - Twine(source=twine_file) + Twine(source=os.path.join(self.path, "twines", "invalid_json_twine.json")) if __name__ == "__main__": diff --git a/tests/test_utils.py b/tests/test_utils.py index f26e31d..e8a3b61 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ import json +import os import unittest from unittest import mock import numpy as np @@ -15,7 +16,7 @@ class TestUtils(BaseTestCase): def test_load_json_with_file_like(self): """ Ensures that json can be loaded from a file-like object """ - file_name = self.path + "twines/valid_schema_twine.json" + file_name = os.path.join(self.path, "twines", "valid_schema_twine.json") with open(file_name, "r") as file_like: data = load_json(file_like) for key in data.keys(): diff --git a/twined/twine.py b/twined/twine.py index 138dead..a180c83 100644 --- a/twined/twine.py +++ b/twined/twine.py @@ -67,7 +67,7 @@ def _load_twine(self, source=None): raw = {} logger.warning("No twine source specified. Loading empty twine.") else: - raw = self._load_json("twine", source, allowed_kinds=("file-like", "filename", "string")) + self._raw = self._load_json("twine", source, allowed_kinds=("file-like", "filename", "string", "object")) self._validate_against_schema("twine", raw) self._validate_twine_version(twine_file_twined_version=raw.get("twined_version", None))