From 260b1681efd26d440ae645244a0496552a812414 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Tue, 25 Aug 2020 17:59:46 +0200 Subject: [PATCH] initial test of list_resource_candidates --- ocrd_utils/ocrd_utils/os.py | 6 ++--- tests/processor/test_processor.py | 3 +++ tests/utils/test_os.py | 43 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests/utils/test_os.py diff --git a/ocrd_utils/ocrd_utils/os.py b/ocrd_utils/ocrd_utils/os.py index 69ac1b018..19e9cfa9a 100644 --- a/ocrd_utils/ocrd_utils/os.py +++ b/ocrd_utils/ocrd_utils/os.py @@ -60,9 +60,9 @@ def list_resource_candidates(executable, fname, cwd=os.getcwd()): candidates += [join(x, fname) for x in os.environ[processor_path_var].split(':')] if 'VIRTUAL_ENV' in os.environ: candidates.append(join(os.environ['VIRTUAL_ENV'], 'share', executable, fname)) - candidates.append(join(XDG_DATA_HOME), executable, fname) - candidates.append(join(XDG_CONFIG_HOME), executable, fname) - candidates.append(join(XDG_CACHE_HOME), executable, fname) + candidates.append(join(XDG_DATA_HOME, executable, fname)) + candidates.append(join(XDG_CONFIG_HOME, executable, fname)) + candidates.append(join(XDG_CACHE_HOME, executable, fname)) return candidates def list_all_resources(executable): diff --git a/tests/processor/test_processor.py b/tests/processor/test_processor.py index f2e91f6de..b97cefb1d 100644 --- a/tests/processor/test_processor.py +++ b/tests/processor/test_processor.py @@ -89,5 +89,8 @@ def test_run_cli(self): resolver=Resolver(), ) + def test_resolve_files(self): + pass + if __name__ == "__main__": main() diff --git a/tests/utils/test_os.py b/tests/utils/test_os.py new file mode 100644 index 000000000..01c043715 --- /dev/null +++ b/tests/utils/test_os.py @@ -0,0 +1,43 @@ +from tempfile import mkdtemp +from tests.base import TestCase, main, assets +from shutil import rmtree +from os import environ as ENV, getcwd +from os.path import expanduser, join + +from ocrd_utils.os import ( + list_resource_candidates +) + +class TestOsUtils(TestCase): + + def setUp(self): + self.tempdir_path = mkdtemp() + self.tempdir_venv = mkdtemp() + ENV['OCRD_DUMMY_PATH'] = self.tempdir_path + self.VIRTUAL_ENV = ENV['VIRTUAL_ENV'] + ENV['VIRTUAL_ENV'] = self.tempdir_venv + + def tearDown(self): + rmtree(self.tempdir_path) + rmtree(self.tempdir_venv) + del ENV['OCRD_DUMMY_PATH'] + ENV['VIRTUAL_ENV'] = self.VIRTUAL_ENV + + def test_resolve_basic(self): + fname = 'foo.bar' + cands = list_resource_candidates('ocrd-dummy', fname) + print(getcwd()) + cands = [x.replace(getcwd(), '$PWD').replace(expanduser('~'), '$HOME') for x in cands] + self.assertEqual(cands, [join(x, fname) for x in [ + '$PWD', + self.tempdir_path, + join(self.tempdir_venv, 'share', 'ocrd-dummy'), + '$HOME/.local/share/ocrd-dummy', + '$HOME/.config/ocrd-dummy', + '$HOME/.cache/ocrd-dummy', + ]]) + + + +if __name__ == '__main__': + main(__file__)