Skip to content

Commit

Permalink
fix: Issue 344 checked rc for commands in tests and removed dependenc…
Browse files Browse the repository at this point in the history
…y on dictdiffer (#440)

Signed-off-by: FrankSuits <frankst@au1.ibm.com>
  • Loading branch information
fsuits authored Apr 6, 2021
1 parent eedf171 commit acc337b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ dev =
python-semantic-release
pep8-naming
pytest-random-order
dictdiffer
python-dateutil
mypy
# # Docs website
Expand Down
6 changes: 3 additions & 3 deletions tests/trestle/core/commands/add_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_run(tmp_path, sample_catalog_minimal):
]

with patch.object(sys, 'argv', testargs):
Trestle().run()
assert Trestle().run() == 0

actual_catalog = Catalog.oscal_read(catalog_def_file)
assert expected_catalog_roles2_rp == actual_catalog
Expand All @@ -170,7 +170,7 @@ def test_striped_model(tmp_path, sample_catalog_minimal):
os.chdir(catalog_def_dir)
testargs = ['trestle', 'split', '-f', 'catalog.json', '-e', 'catalog.metadata']
with patch.object(sys, 'argv', testargs):
Trestle().run()
assert Trestle().run() == 0

# Now that the metadata has been split, add of catalog.metadata.roles will error,
# but add of catalog.back-matter will pass
Expand All @@ -188,7 +188,7 @@ def test_striped_model(tmp_path, sample_catalog_minimal):
expected_catalog = current_catalog

with patch.object(sys, 'argv', testargs):
Trestle().run()
assert Trestle().run() == 0

actual_model, _ = get_stripped_contextual_model()
actual_catalog = actual_model.oscal_read(pathlib.Path('catalog.json'))
Expand Down
2 changes: 1 addition & 1 deletion tests/trestle/core/commands/create_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_broken_args(tmp_trestle_dir: pathlib.Path) -> None:
# correct behavior
with mock.patch.object(sys, 'argv', testargs):
rc = Trestle().run()
assert rc == 0
assert rc == 0
# correct behavior
testargs[2] = 'bad_name'
with mock.patch.object(sys, 'argv', testargs):
Expand Down
4 changes: 1 addition & 3 deletions tests/trestle/core/commands/merge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import shutil
from pathlib import Path

from dictdiffer import diff

from tests import test_utils

import trestle.oscal.catalog as oscatalog
Expand Down Expand Up @@ -313,7 +311,7 @@ def test_merge_plan_simple_list(testdata_dir, tmp_trestle_dir):
generated_plan = MergeCmd.merge(ElementPath('metadata.roles'))

# Assert the generated plan matches the expected plan'
assert len(list(diff(generated_plan, expected_plan))) == 0
assert generated_plan == expected_plan


def test_split_merge(testdata_dir, tmp_trestle_dir):
Expand Down
4 changes: 2 additions & 2 deletions tests/trestle/core/commands/remove_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_run(tmp_path, sample_catalog_minimal):
testargs = ['trestle', 'remove', '-f', str(catalog_def_file), '-e', 'catalog.metadata.responsible-parties']

with patch.object(sys, 'argv', testargs):
Trestle().run()
assert Trestle().run() == 0

actual_catalog = Catalog.oscal_read(catalog_def_file)
assert expected_catalog_no_rp == actual_catalog
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_run(tmp_path, sample_catalog_minimal):
]

with patch.object(sys, 'argv', testargs):
Trestle().run()
assert Trestle().run() == 0

actual_catalog = Catalog.oscal_read(catalog_def_file_2)
assert expected_catalog_no_rp == actual_catalog
4 changes: 2 additions & 2 deletions tests/trestle/core/commands/split_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def prepare_target_def_file() -> None:
)

os.chdir(target_def_dir)
cmd._run(args)
assert cmd._run(args) == 0
os.chdir(cwd)
check_split_files()

Expand All @@ -302,7 +302,7 @@ def prepare_target_def_file() -> None:
file='target-definition.yaml', element='target-definition.metadata,target-definition.targets.*', verbose=0
)
os.chdir(target_def_dir)
cmd._run(args)
assert cmd._run(args) == 0
os.chdir(cwd)
check_split_files()

Expand Down
8 changes: 3 additions & 5 deletions tests/trestle/utils/load_distributed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import shutil
from pathlib import Path

import dictdiffer

from tests import test_utils

from trestle.oscal.catalog import Catalog, ResponsibleParty, Role
Expand Down Expand Up @@ -97,15 +95,15 @@ def test_load_dict(testdata_dir, tmp_trestle_dir):
actual_model_type, actual_model_alias, actual_model_instance = _load_dict(
catalog_dir / 'metadata/responsible-parties')

expexted_model_instance = {
expected_model_instance = {
'contact': ResponsibleParty.oscal_read(
catalog_dir / 'metadata/responsible-parties/contact__responsible-party.json'
),
'creator': ResponsibleParty.oscal_read(
catalog_dir / 'metadata/responsible-parties/creator__responsible-party.json'
)
}
assert len(list(dictdiffer.diff(actual_model_instance, expexted_model_instance))) == 0
assert actual_model_instance == expected_model_instance
assert actual_model_alias == 'catalog.metadata.responsible-parties'

expected_model_type, _ = fs.get_contextual_model_type((catalog_dir / 'metadata/responsible-parties/').absolute())
Expand Down Expand Up @@ -135,4 +133,4 @@ def test_load_distributed(testdata_dir, tmp_trestle_dir):

assert actual_model_type == expected_model_type
assert actual_model_alias == 'catalog'
assert len(list(dictdiffer.diff(expected_model_instance, actual_model_instance))) == 0
assert expected_model_instance == actual_model_instance

0 comments on commit acc337b

Please sign in to comment.