Exemplo n.º 1
0
 def test_verify_path_exists(self):
     """ tests that file exists function works """
     should_exist = verify_path_exists('/tmp/avro/nest/test2.avsc')
     should_not_exist = verify_path_exists('/tmp/avro/test2.avsc')
     self.assertTrue(should_exist,
                     'expected /tmp/avro/nest/test2.avsc to exist')
     self.assertFalse(should_not_exist,
                      'expected /tmp/avro/test2.avsc to not exist')
Exemplo n.º 2
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/')
Exemplo n.º 3
0
        def test_get_or_create_path(self):
            """ tests that get_or_create_path works """
            path = '/tmp/test'

            get_or_create_path(path=path)

            self.assertTrue(verify_path_exists('/tmp/test'),
                            'should have created path at /tmp/test')
            os.rmdir(path)

            os.chdir('/tmp')

            get_or_create_path(path='test')

            self.assertTrue(
                verify_path_exists('/tmp/test'),
                'should have created path at /tmp/test from relative path')
            os.rmdir(path)
Exemplo n.º 4
0
    def test_get_or_create_path(self):
        """ tests that get_or_create_path works """
        path = self.test_dir

        get_or_create_path(path=path)

        self.assertTrue(verify_path_exists(self.test_dir),
                        'should have created path at /tmp/test')
        os.rmdir(path)

        os.chdir(self.root)

        get_or_create_path(path='test')

        self.assertTrue(
            verify_path_exists(self.test_dir),
            'should have created path at /tmp/test from relative path')
        shutil.rmtree(path)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def __init__(self, directory: str = None, file: str = None) -> None:
        """ Initializer should just create a list of files to process

        Parameters
        ----------
            directory: str
                Directory of files to read
                Cannot be used with "file" param

            file: str
                path of avsc file to compile
                Cannot be used with "directory" param

        Returns
        -------
            None
        """

        # initialize cental object
        self.obj = {}
        self.file_tree = None

        if directory:
            if os.path.isfile(directory):
                raise OSError(f'{directory} is a file!')
            files = get_avsc_files(directory)
            if files:
                self.files = files
                self.obj['root_dir'] = get_system_path(directory)
                self.obj['read_type'] = 'directory'
            else:
                raise NoFilesError(f'No avsc files found in {directory}')

        elif file:
            if not verify_path_exists(file):
                raise MissingFileError(f'{file} does not exist!')
            if os.path.isdir(file):
                raise IsADirectoryError(f'{file} is a directory!')
            syspath = get_system_path(file)
            self.files = [syspath]
            self.obj['read_type'] = 'file'

        else:
            raise NoFileOrDir

        self.obj['avsc'] = []