Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
        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/')
Ejemplo n.º 4
0
    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)