From f1a1bea8987a0f85cb49995f938fe47c71a757e7 Mon Sep 17 00:00:00 2001 From: Joel Dunham Date: Fri, 10 Nov 2017 16:59:42 -0800 Subject: [PATCH] fix --- tests/test_mets.py | 13 ++++++++++++- tests/test_validate.py | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_mets.py b/tests/test_mets.py index d089549..c14fa26 100644 --- a/tests/test_mets.py +++ b/tests/test_mets.py @@ -581,8 +581,19 @@ def test_parse_production_pointer_file(self): def assert_mets_valid(self, mets_doc, schematron=metsrw.AM_SCT_PATH): is_valid, report = metsrw.validate(mets_doc, schematron=schematron) - if not is_valid: + try: + assert is_valid + except AssertionError: raise AssertionError(report['report']) def assert_pointer_valid(self, mets_doc): self.assert_mets_valid(mets_doc, schematron=metsrw.AM_PNTR_SCT_PATH) + + +def test_invalid_mets_file(): + mets_path = 'fixtures/mets_without_groupid_in_file.xml' + mets_doc = etree.parse(mets_path) + schematron = metsrw.AM_SCT_PATH + is_valid, report = metsrw.validate(mets_doc, schematron=schematron) + assert not is_valid + assert 'An amdSec element MUST contain a techMD' in report['report'] diff --git a/tests/test_validate.py b/tests/test_validate.py index ee4a307..dfb340f 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -22,3 +22,12 @@ def test_get_schematron(mocker): with pytest.raises(IOError): metsrw.get_schematron(bad_path) get_file_path.assert_called_once_with(bad_path) + + def mockisfile(path): + if path == bad_path: + return False + return True + mocker.patch.object(os.path, 'isfile', mockisfile) + with pytest.raises(IOError): + metsrw.get_schematron(bad_path) + assert os.path.isfile.call_count == 2