def test_validate_missing_py(self): dirpath = MockDir({ 'module.json': b'', }) with self.assertRaisesRegex(ValueError, 'Missing ".py" module-code file'): ModuleFiles.load_from_dirpath(dirpath)
def test_validate_missing_json(self): dirpath = MockDir({ 'module.py': b'', }) with self.assertRaisesRegex( ValueError, 'Missing ".json" or ".yaml" module-spec file'): ModuleFiles.load_from_dirpath(dirpath)
def test_ignore_test_py(self): dirpath = MockDir({ 'module.json': b'', 'module.py': b'', 'test_module.py': b'', }) module_files = ModuleFiles.load_from_dirpath(dirpath) self.assertEqual(module_files.code.name, 'module.py')
def test_validate_extra_py(self): dirpath = MockDir({ 'module.json': b'{}', 'module.py': b'', 'module2.py': b'', }) with self.assertRaisesRegex(ValueError, 'Multiple.*py.*files'): ModuleFiles.load_from_dirpath(dirpath)
def test_happy_path(self): dirpath = MockDir( {"module.json": b"", "module.py": b"", "module.html": b"", "module.js": b""} ) module_files = ModuleFiles.load_from_dirpath(dirpath) self.assertEqual(module_files.spec.name, "module.json") self.assertEqual(module_files.code.name, "module.py") self.assertEqual(module_files.html.name, "module.html") self.assertEqual(module_files.javascript.name, "module.js")
def test_validate_max_1_js(self): dirpath = MockDir({ 'module.json': b'', 'module.py': b'', 'module.js': b'', 'extra.js': b'', }) with self.assertRaisesRegex(ValueError, 'Multiple.*js.*files'): ModuleFiles.load_from_dirpath(dirpath)
def test_ignore_package_json(self): dirpath = MockDir({ 'module.json': b'', 'module.py': b'', 'package.json': b'', 'package-lock.json': b'', }) module_files = ModuleFiles.load_from_dirpath(dirpath) self.assertEqual(module_files.spec.name, 'module.json')
def test_validate_max_1_html(self): dirpath = MockDir( { "module.json": b"", "module.py": b"", "module.html": b"", "extra.html": b"", } ) with self.assertRaisesRegex(ValueError, "Multiple.*html.*files"): ModuleFiles.load_from_dirpath(dirpath)
def test_ignore_package_json(self): dirpath = MockDir( { "module.json": b"", "module.py": b"", "package.json": b"", "package-lock.json": b"", } ) module_files = ModuleFiles.load_from_dirpath(dirpath) self.assertEqual(module_files.spec.name, "module.json")
def test_happy_path(self): dirpath = MockDir({ 'module.json': b'', 'module.py': b'', 'module.html': b'', 'module.js': b'', }) module_files = ModuleFiles.load_from_dirpath(dirpath) self.assertEqual(module_files.spec.name, 'module.json') self.assertEqual(module_files.code.name, 'module.py') self.assertEqual(module_files.html.name, 'module.html') self.assertEqual(module_files.javascript.name, 'module.js')
def test_validate_detect_python_syntax_errors(self): test_dir = MockDir({ "badpy.json": json.dumps( dict( name="Syntax-error Python", id_name="badpy", category="Clean", parameters=[], )).encode("utf-8"), "badpy.py": b'def render(table, params):\n cols = split(","', }) with self.assertRaises(ValueError): import_module_from_directory("123456", test_dir)
def _validate(self, data): dirpath = MockDir({"module.py": data.encode("utf-8")}) path = dirpath / "module.py" validate_python_functions(path)
def test_ignore_test_py(self): dirpath = MockDir({"module.json": b"", "module.py": b"", "test_module.py": b""}) module_files = ModuleFiles.load_from_dirpath(dirpath) self.assertEqual(module_files.code.name, "module.py")
def test_validate_extra_py(self): dirpath = MockDir({"module.json": b"{}", "module.py": b"", "module2.py": b""}) with self.assertRaisesRegex(ValueError, "Multiple.*py.*files"): ModuleFiles.load_from_dirpath(dirpath)
def _validate(self, data): dirpath = MockDir({ 'module.py': data.encode('utf-8'), }) path = dirpath / 'module.py' validate_python_functions(path)