def _write_file(self, filename: str, filetext: str, namespace: str) -> None: """ writes python filetext to appropriate namespace """ verify_or_create_namespace_path(rootdir=self.root_dir, namespace=namespace) filepath = self.root_dir + namespace.replace( '.', '/') + '/' + filename + '.py' # NOQA with open(filepath, 'w') as f: f.write(filetext)
def _write_init_file(self, imports: set, namespace: str) -> None: """ writes __init__.py files for namespace imports""" template = self.template_env.get_template('files/init.j2') filetext = template.render(imports=imports, pip_import=self.pip_import) verify_or_create_namespace_path(rootdir=self.root_dir, namespace=namespace) filepath = self.root_dir + namespace.replace( '.', '/') + '/' + '__init__.py' # NOQA with open(filepath, 'w') as f: f.write(filetext)
def test_verify_or_create_namespace_path(self): """ tests that verify_or_create_namespace_path works """ rootdir = '/tmp' namespace = 'test.namespace.path' verify_or_create_namespace_path(rootdir=rootdir, namespace=namespace) self.assertTrue(verify_path_exists('/tmp/test/namespace/path/'), 'should have created the path from a namespace') verify_or_create_namespace_path(rootdir=rootdir, namespace=namespace) self.assertTrue(verify_path_exists('/tmp/test/namespace/path/'), 'should have created the path from a namespace') os.rmdir('/tmp/test/')
def test_verify_or_create_namespace_path(self): """ tests that verify_or_create_namespace_path works """ rootdir = self.root namespace = 'test.namespace.path' verify_or_create_namespace_path(rootdir=rootdir, namespace=namespace) self.assertTrue( verify_path_exists( get_joined_path(self.test_dir, 'namespace', 'path')), 'should have created the path from a namespace') verify_or_create_namespace_path(rootdir=rootdir, namespace=namespace) self.assertTrue( verify_path_exists( get_joined_path(self.test_dir, 'namespace', 'path')), 'should have created the path from a namespace') shutil.rmtree(self.test_dir)