Skip to content

Commit

Permalink
initial test of list_resource_candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Oct 13, 2020
1 parent 297a0f3 commit 260b168
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ocrd_utils/ocrd_utils/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions tests/processor/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,8 @@ def test_run_cli(self):
resolver=Resolver(),
)

def test_resolve_files(self):
pass

if __name__ == "__main__":
main()
43 changes: 43 additions & 0 deletions tests/utils/test_os.py
Original file line number Diff line number Diff line change
@@ -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__)

0 comments on commit 260b168

Please sign in to comment.