Skip to content

Commit

Permalink
Merge pull request #873 from OCR-D/macos
Browse files Browse the repository at this point in the history
try testing OSX, #850
  • Loading branch information
kba committed Aug 15, 2022
2 parents 4148a88 + aa4b776 commit ceb9992
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -66,3 +80,4 @@ workflows:
- test-python37
- test-python38
- test-python39
- test-macos
8 changes: 4 additions & 4 deletions ocrd_utils/ocrd_utils/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions tests/cli/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'
Expand Down
14 changes: 10 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from ocrd_models.utils import xmllint_format
from ocrd_models import OcrdMets


class TestUtils(TestCase):

def test_abspath(self):
Expand Down Expand Up @@ -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'):
Expand Down
4 changes: 2 additions & 2 deletions tests/validator/test_workspace_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ceb9992

Please sign in to comment.