Skip to content

Commit

Permalink
Merge 8e38fc6 into 67d5ae7
Browse files Browse the repository at this point in the history
  • Loading branch information
metatoaster committed Apr 28, 2018
2 parents 67d5ae7 + 8e38fc6 commit 7e228a3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Changelog
- Correctly locate the subparser(s) that were responsible for whatever
arguments they cannot recognize; includes cleaning up the interactions
between the runtime and argparser classes and Python 3.7 compatibility
fixes. [
fixes. Also cleaned up various log and error messages. [
`#41 <https://github.com/calmjs/calmjs/issues/41>`_
`#42 <https://github.com/calmjs/calmjs/issues/42>`_
]

3.0.0 (2018-01-10)
Expand Down
26 changes: 23 additions & 3 deletions src/calmjs/tests/test_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,13 +1178,33 @@ def test_toolchain_standard_build_dir_set(self):
not_exist = join(spec['build_dir'], 'not_exist')

spec['build_dir'] = not_exist
with self.assertRaises(OSError):
# well, dir does not exist
self.toolchain(spec)
with pretty_logging(stream=StringIO()) as s:
with self.assertRaises(OSError):
# well, dir does not exist
self.toolchain(spec)

# Manually specified build_dirs do not get modified if they just
# simply don't exist.
self.assertEqual(spec['build_dir'], not_exist)
self.assertIn(not_exist, s.getvalue())
self.assertIn("is not a directory", s.getvalue())

def test_toolchain_standard_build_dir_set_not_dir(self):
spec = Spec()
some_file = join(mkdtemp(self), 'some_file')

with open(some_file, 'w'):
pass

spec['build_dir'] = some_file
with pretty_logging(stream=StringIO()) as s:
with self.assertRaises(OSError):
# well, dir is not a dir.
self.toolchain(spec)

self.assertEqual(spec['build_dir'], some_file)
self.assertIn(some_file, s.getvalue())
self.assertIn("is not a directory", s.getvalue())

def test_toolchain_standard_build_dir_remapped(self):
"""
Expand Down
12 changes: 11 additions & 1 deletion src/calmjs/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,19 @@ def test_raise_os_error_file_not_found(self):
def test_raise_os_error_not_dir(self):
e = OSError if sys.version_info < (
3, 3) else NotADirectoryError # noqa: F821
with self.assertRaises(e):
with self.assertRaises(e) as exc:
raise_os_error(errno.ENOTDIR)

self.assertIn('Not a directory', str(exc.exception))

def test_raise_os_error_not_dir_with_path(self):
e = OSError if sys.version_info < (
3, 3) else NotADirectoryError # noqa: F821
with self.assertRaises(e) as exc:
raise_os_error(errno.ENOTDIR, 'some_path')

self.assertIn("Not a directory: 'some_path'", str(exc.exception))


class LoggingTestCase(unittest.TestCase):
"""
Expand Down
5 changes: 3 additions & 2 deletions src/calmjs/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,15 +1542,16 @@ def calf(self, spec):
mkdir(build_dir)
spec[BUILD_DIR] = build_dir
else:
if not exists(spec[BUILD_DIR]):
raise_os_error(errno.ENOTDIR)
check = realpath(spec[BUILD_DIR])
if check != spec[BUILD_DIR]:
spec[BUILD_DIR] = check
logger.warning(
"realpath of build_dir resolved to '%s', spec is updated",
check
)
if not isdir(check):
logger.error("build_dir %r is not a directory", check)
raise_os_error(errno.ENOTDIR, check)

# Finally, handle setup which may set up the deferred advices,
# as all the toolchain (and its runtime and/or its parent
Expand Down
5 changes: 3 additions & 2 deletions src/calmjs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ def fork_exec(args, stdin='', **kwargs):
return (stdout.decode(locale), stderr.decode(locale))


def raise_os_error(_errno):
def raise_os_error(_errno, path=None):
"""
Helper for raising the correct exception under Python 3 while still
being able to raise the same common exception class in Python 2.7.
"""

raise OSError(_errno, strerror(_errno))
msg = "%s: '%s'" % (strerror(_errno), path) if path else strerror(_errno)
raise OSError(_errno, msg)


def which(cmd, mode=os.F_OK | os.X_OK, path=None):
Expand Down

0 comments on commit 7e228a3

Please sign in to comment.