parameters-as-json: test failurew
@@ -7,7 +7,12 @@ from click.testing import CliRunner
from tests.base import TestCase, assets, main, copy_of_directory # pylint: disable=import-error, no-name-in-module
from ocrd import Processor
-from ocrd.decorators import ocrd_cli_options, ocrd_loglevel, ocrd_cli_wrap_processor
+from ocrd.decorators import (
+ ocrd_cli_options,
+ ocrd_loglevel,
+ ocrd_cli_wrap_processor,
+ _parse_json_string_or_file
+) # pylint: disable=protected-access
from ocrd_utils.logging import setOverrideLogLevel, initLogging
from ocrd_utils import pushd_popd
@@ -83,12 +88,13 @@ class TestDecorators(TestCase):
result = self.runner.invoke(cli_dummy_processor, ['--mets', 'mets.xml'])
self.assertEqual(result.exit_code, 0)
- def test_parameters(self):
- from ocrd.decorators import _parse_json_string_or_file # pylint: disable=protected-access
+ def test_parameters0(self):
self.assertEqual(_parse_json_string_or_file(None, None), {})
self.assertEqual(_parse_json_string_or_file(None, None, '{}'), {})
self.assertEqual(_parse_json_string_or_file(None, None, '{"foo": 32}'), {'foo': 32})
self.assertEqual(_parse_json_string_or_file(None, None, '{"foo": 32}'), {'foo': 32})
+
+ def test_parameter_file(self):
with TemporaryDirectory() as tempdir:
paramfile = str(Path(tempdir, '{}')) # XXX yes, the file is called '{}'
with open(paramfile, 'w') as f:
@@ -97,6 +103,12 @@ class TestDecorators(TestCase):
with pushd_popd(tempdir):
self.assertEqual(_parse_json_string_or_file(None, None), {'bar': 42})
+ def test_parameters_invalid(self):
+ with self.assertRaisesRegex(ValueError, 'Not a valid JSON object'):
+ _parse_json_string_or_file(None, None, '[]')
+ with self.assertRaisesRegex(ValueError, 'Error parsing'):
+ _parse_json_string_or_file(None, None, '[}')
+
if __name__ == '__main__':
main()
