diff --git a/.circleci/config.yml b/.circleci/config.yml index 661b64188b..3538f047ac 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,21 @@ version: 2 +orbs: + python: circleci/python@2.0.3 + jobs: + test-macos: + macos: + xcode: "12.5.1" + # resource_class: macos.x86.medium.gen2 + working_directory: ~/ocrd-core + steps: + - checkout + - run: HOMEBREW_NO_AUTO_UPDATE=1 brew install imagemagick + - run: make deps-test install PIP=pip3 + - run: make test PYTHON=python3 + test-python36: docker: - image: python:3.6.12 @@ -66,3 +80,4 @@ workflows: - test-python37 - test-python38 - test-python39 + - test-macos diff --git a/ocrd_utils/ocrd_utils/os.py b/ocrd_utils/ocrd_utils/os.py index c38811b30e..0595503234 100644 --- a/ocrd_utils/ocrd_utils/os.py +++ b/ocrd_utils/ocrd_utils/os.py @@ -12,7 +12,7 @@ 'atomic_write', ] -from tempfile import TemporaryDirectory +from tempfile import TemporaryDirectory, gettempdir from functools import lru_cache import contextlib from distutils.spawn import find_executable as which @@ -47,16 +47,16 @@ def pushd_popd(newcwd=None, tempdir=False): oldcwd = getcwd() except FileNotFoundError: # This happens when a directory is deleted before the context is exited - oldcwd = '/tmp' + oldcwd = gettempdir() try: if tempdir: with TemporaryDirectory() as tempcwd: chdir(tempcwd) - yield tempcwd + yield Path(tempcwd).resolve() else: if newcwd: chdir(newcwd) - yield newcwd + yield Path(newcwd).resolve() finally: chdir(oldcwd) diff --git a/tests/cli/test_workspace.py b/tests/cli/test_workspace.py index 0583df3233..bbbda7ff14 100644 --- a/tests/cli/test_workspace.py +++ b/tests/cli/test_workspace.py @@ -131,6 +131,7 @@ def test_add_remove_force(self): content = 'x' mimetype = 'image/tiff' with TemporaryDirectory() as tempdir: + tempdir = str(Path(tempdir).resolve()) content_file = join(tempdir, 'testfile') with open(content_file, 'w') as f: f.write(content) @@ -236,6 +237,7 @@ def test_add_existing_checked(self): file_grp = 'TEST_GROUP' mimetype = 'image/tiff' with TemporaryDirectory() as tempdir: + tempdir = str(Path(tempdir).resolve()) content_file = join(tempdir, 'test.tif') ws = self.resolver.workspace_from_nothing(directory=tempdir) ws.save_mets() @@ -308,6 +310,7 @@ def test_remove_file_group(self): Test removal of filegrp """ with TemporaryDirectory() as tempdir: + tempdir = str(Path(tempdir).resolve()) wsdir = join(tempdir, 'ws') copytree(assets.path_to('SBB0000F29300010000/data'), wsdir) file_group = 'OCR-D-GT-PAGE' diff --git a/tests/test_utils.py b/tests/test_utils.py index e1da91a586..2d16e7a134 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -45,6 +45,7 @@ from ocrd_models.utils import xmllint_format from ocrd_models import OcrdMets + class TestUtils(TestCase): def test_abspath(self): @@ -146,16 +147,21 @@ def test_pil_version(self): def test_pushd_popd_newcwd(self): cwd = getcwd() - with pushd_popd('/tmp'): - self.assertEqual(getcwd(), '/tmp') + tmp_dir = Path(gettempdir()).resolve() + with pushd_popd(tmp_dir): + self.assertEqual(getcwd(), str(tmp_dir)) self.assertEqual(getcwd(), cwd) + assert getcwd() == cwd def test_pushd_popd_tempdir(self): cwd = getcwd() + tmp_dir = str(Path(gettempdir()).resolve()) with pushd_popd(tempdir=True) as newcwd: - self.assertEqual(getcwd(), newcwd) - self.assertTrue(newcwd.startswith(gettempdir())) + newcwd_str = str(newcwd) + self.assertEqual(getcwd(), newcwd_str) + self.assertTrue(newcwd_str.startswith(tmp_dir)) self.assertEqual(getcwd(), cwd) + assert getcwd() == cwd def test_pushd_popd_bad_call(self): with self.assertRaisesRegex(Exception, 'pushd_popd can accept either newcwd or tempdir, not both'): diff --git a/tests/validator/test_workspace_validator.py b/tests/validator/test_workspace_validator.py index 3648e4c5ad..8438afcfd4 100644 --- a/tests/validator/test_workspace_validator.py +++ b/tests/validator/test_workspace_validator.py @@ -190,7 +190,7 @@ def test_dimensions(self): wsdir = join(tempdir, 'foo') copytree(assets.path_to('kant_aufklaerung_1784/data'), wsdir) with pushd_popd(wsdir): - os.system("""sed -i 's,imageHeight="2083",imageHeight="1234",' OCR-D-GT-PAGE/PAGE_0017_PAGE.xml""") + os.system("""sed -i.bak 's,imageHeight="2083",imageHeight="1234",' OCR-D-GT-PAGE/PAGE_0017_PAGE.xml""") report = WorkspaceValidator.validate( self.resolver, join(wsdir, 'mets.xml'), @@ -229,7 +229,7 @@ def test_pcgtsid(self): with copy_of_directory(assets.path_to('kant_aufklaerung_1784/data')) as wsdir: with pushd_popd(wsdir): # remove the @pcGtsId attribute for testing - os.system("""sed -i 's,pcGtsId.*,pcGtsId="foo">,' OCR-D-GT-PAGE/PAGE_0017_PAGE.xml""") + os.system("""sed -i.bak 's,pcGtsId.*,pcGtsId="foo">,' OCR-D-GT-PAGE/PAGE_0017_PAGE.xml""") report = WorkspaceValidator.validate(self.resolver, join(wsdir, 'mets.xml')) self.assertIn('pc:PcGts/@pcGtsId differs from mets:file/@ID: "foo" !== "PAGE_0017_PAGE"', report.warnings)