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