Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix "tests/import/module_name/module_name.py" test

  • Loading branch information...
commit 822e53a21936570021a0d6b4ce8af90b131c5821 1 parent 3fa5d14
@thenewguy authored
View
15 pyjaco/__init__.py
@@ -39,7 +39,7 @@
from _version import get_version, parse_version
except ImportError:
from .._version import get_version, parse_version
-from compiler.utils import special_globals, dotted_to_hierarchy
+from compiler.utils import special_globals, create_dotted_path, dotted_to_hierarchy
__version__ = get_version()
__version_info__ = parse_version(__version__)
@@ -155,16 +155,7 @@ def append_class(self, code, name = None):
def append_module(self, code, path, base = None):
# determine module name characteristics
- path = os.path.abspath(path)
- if base is None:
- base = os.getcwd()
- base = os.path.abspath(base)
- commonprefix = os.path.commonprefix([path, base])
- path, base, commonprefix = [x.replace('\\','/') for x in (path, base, commonprefix)]
- filename = path[len(commonprefix):].lstrip('/')
- dotted = os.path.splitext(filename)[0].replace('/', '.')
- if dotted.endswith('.__init__'):
- dotted = dotted[:-9]
+ (path, base, filename, dotted) = create_dotted_path(path, base)
# verify dotted path is valid
for part in dotted.split("."):
@@ -175,7 +166,7 @@ def append_module(self, code, path, base = None):
path
)
)
-
+
# make the module name available to the compilers
self.shared_state["module"] = dotted
View
13 pyjaco/compiler/utils.py
@@ -6,6 +6,19 @@
"__module__": None
}
+def create_dotted_path(path, base = None):
+ path = os.path.abspath(path)
+ if base is None:
+ base = os.getcwd()
+ base = os.path.abspath(base)
+ commonprefix = os.path.commonprefix([path, base])
+ path, base, commonprefix = [x.replace('\\','/') for x in (path, base, commonprefix)]
+ filename = path[len(commonprefix):].lstrip('/')
+ dotted = os.path.splitext(filename)[0].replace('/', '.')
+ if dotted.endswith('.__init__'):
+ dotted = dotted[:-9]
+ return (path, base, filename, dotted)
+
def dotted_to_hierarchy(dotted):
hierarchy = []
pieces = "%s." % dotted
View
6 testtools/known_to_fail.py
@@ -44,8 +44,4 @@
"tests/modules/rng.py",
"tests/modules/rng_as_module.py",
-
- "tests/import/module_name/module_name.py"# javascript module path is different from
- # python module path so equality fails, but
- # what the test is actually testing passes
- ]
+]
View
33 testtools/tests.py
@@ -37,10 +37,11 @@ def create_cases():
module_test_cases.addTest(
unittest.TestLoader().loadTestsFromTestCase(
util.compile_as_module_and_run_file_test(
- test_path,
- os.path.basename(test_path),
- uses_imports = False,
- output_postfix = "as_module"
+ test_path,
+ os.path.basename(test_path),
+ uses_imports = False,
+ output_postfix = "as_module",
+ base = os.path.dirname(test_path).replace("\\", "/")
)
)
)
@@ -93,7 +94,8 @@ def create_cases():
test_path,
os.path.basename(test_path),
uses_imports = False,
- output_postfix = test_paths_module_postfix
+ output_postfix = test_paths_module_postfix,
+ base = os.path.dirname(test_path).replace("\\", "/")
)
)
)
@@ -104,7 +106,8 @@ def create_cases():
test_path,
os.path.basename(test_path),
uses_imports = False,
- output_postfix = test_paths_module_postfix
+ output_postfix = test_paths_module_postfix,
+ base = os.path.dirname(test_path).replace("\\", "/")
)
)
)
@@ -115,8 +118,8 @@ def create_cases():
test_cases.addTest(
unittest.TestLoader().loadTestsFromTestCase(
util.compile_as_module_and_run_file_test(
- test_path,
- os.path.basename(test_path)
+ test_path,
+ os.path.basename(test_path)
)
)
)
@@ -139,9 +142,10 @@ def create_cases():
module_test_cases.addTest(
unittest.TestLoader().loadTestsFromTestCase(
util.compile_as_module_and_run_file_test(
- test_path,
- os.path.basename(test_path),
- uses_imports = True
+ test_path,
+ os.path.basename(test_path),
+ uses_imports = True,
+ base = os.path.dirname(test_path).replace("\\", "/")
)
)
)
@@ -149,9 +153,10 @@ def create_cases():
module_failing_test_cases.addTest(
unittest.TestLoader().loadTestsFromTestCase(
util.compile_as_module_and_run_file_failing_test(
- test_path,
- os.path.basename(test_path),
- uses_imports = True
+ test_path,
+ os.path.basename(test_path),
+ uses_imports = True,
+ base = os.path.dirname(test_path).replace("\\", "/")
)
)
)
View
13 testtools/util.py
@@ -11,6 +11,7 @@
import subprocess
import posixpath
from os.path import split, splitext
+from pyjaco.compiler.utils import create_dotted_path
def run_command(cmd):
return subprocess.call(cmd, shell = True)
@@ -179,7 +180,7 @@ def postfix_path_filename(file_path, output_postfix=None):
output_path = file_path
return output_path
-def compile_as_module_and_run_file_test(file_path, file_name=None, output_postfix=None, uses_imports = False):
+def compile_as_module_and_run_file_test(file_path, file_name=None, output_postfix=None, uses_imports = False, base = None):
"""Creates a test that compiles as a module and runs the python file as js"""
file_name = file_name if file_name else file_path
@@ -199,6 +200,7 @@ class CompileAsModuleAndRunFile(unittest.TestCase):
"js_error": output_path + ".js.err",
"compiler_error": output_path + ".comp.err",
"name": file_name,
+ "base": '--base "%s"' % base if base else ''
}
def reportProgres(self):
"""Should be overloaded by the test result class"""
@@ -220,7 +222,7 @@ def runTest(self):
except OSError:
mtime_js_res = 0
compile_command = (
- '%(py_executable)s pyjs.py -I -q -m '
+ '%(py_executable)s pyjs.py -I -q --as-module %(base)s '
'"%(py_path)s" > "%(js_path)s" 2> '
'"%(compiler_error)s"'
) % self.templ
@@ -238,10 +240,11 @@ def runTest(self):
continue
js_path = py_path + ".js"
cmd = (
- '%(py_executable)s pyjs.py -q -m '
+ '%(py_executable)s pyjs.py -q --as-module %(base)s '
'"%(py_path)s" > "%(js_path)s"'
) % {
"py_executable": self.templ["py_executable"],
+ "base": self.templ["base"],
"py_path": py_path,
"js_path": js_path
}
@@ -254,9 +257,11 @@ def runTest(self):
'"%(js_error)s"'
) % templ
+ # determine module name characteristics for the run file
+ dotted = create_dotted_path(self.templ["py_path"], base)[-1]
+
# create javascript run file
with open(self.templ['js_run_file'], 'w') as f:
- dotted = os.path.splitext(self.templ['py_path'])[0].replace("\\","/").replace("/",".")
f.write("\n")
f.write("$PY.run_module('%s', '__main__')" % dotted)
Please sign in to comment.
Something went wrong with that request. Please try again.