예제 #1
0
def test_scan_scan_xz():
    """ Unit test for scan method, lzma case. """
    file_io = FileIO()

    for method_row, util_row in zip(file_io.scan(TEST_CSV_XZ),
                                    util_test_csv(TEST_CSV)):
        assert method_row == util_row
예제 #2
0
def test_scan_scan_bzip2():
    """ Unit test for scan method, gzip case. """
    file_io = FileIO()

    for method_row, util_row in zip(file_io.scan(TEST_CSV_BZ2),
                                    util_test_csv(TEST_CSV)):
        assert method_row == util_row
예제 #3
0
def test_scan_tar_files():
    """Unit test for method scan, compressed tar file case."""
    file_io = FileIO()

    for ffile in os.listdir(TEST_TAR_LOCATION):
        for dfile in file_io.scan(os.path.join(TEST_TAR_LOCATION, ffile)):
            assert os.path.exists(dfile)
예제 #4
0
def test_scan_csv():
    """ Unit test for scan method, txt or csv case. """

    file_io = FileIO()

    for method_row, util_row in zip(file_io.scan(TEST_CSV),
                                    util_test_csv(TEST_CSV)):
        assert method_row == util_row
예제 #5
0
    def test_scan_unknown_file(self):
        """
        Unit test for scan method, unknown file case
        """
        file_io = FileIO()

        with self.assertRaises(FileTypeNotSupportedYet):
            next(file_io.scan(TEST_UNKNOWN))
예제 #6
0
def test_infer_file_type_from_uri_remote():
    """
    Unit test for method infer_file_type_from_uri,
    remote case.
    """
    file_io = FileIO()

    assert file_io.infer_file_type_from_uri(TEST_URL) == 'JPG'
예제 #7
0
def test_scan_compressed_tar_file_http():
    """Unit test for method scan_compressed_tar_file, http case."""
    test_uri = 'http://localhost:8888/images.tar.xz'
    test_file_reader = 'r|xz'

    file_io = FileIO()

    for ffile in file_io.scan_compressed_tar_file(test_uri, test_file_reader):
        assert os.path.exists(ffile)
예제 #8
0
def test_infer_file_type_from_uri_no_mimetype():
    """
    Unit test for method infer_file_type_from_uri,
    no mimetype case
    """
    file_io = FileIO()

    assert file_io.infer_file_type_from_uri(TEST_LOCAL,
                                            mimetype=False) == 'JPG'
예제 #9
0
def test_infer_file_type_from_uri_with_mimetype():
    """
    Unit test for method infer_file_type_from_uri,
    with mimetype case
    """
    file_io = FileIO()

    _, mime = file_io.infer_file_type_from_uri(TEST_LOCAL, mimetype=True)

    assert mime == 'image/jpeg'
예제 #10
0
    def test_infer_file_type_from_uri_unsupported(self):
        """
        Unit test for method infer_file_type_from_uri,
        unsupported file type case
        """
        file_io = FileIO()

        with self.assertRaises(FileTypeNotSupportedYet):
            file_io.infer_file_type_from_uri(TEST_UNSUPPORTED_FILE_TYPE,
                                             mimetype=True)
예제 #11
0
def test_dump():
    """Unit test for method dump."""
    file_io = FileIO()

    file_io.dump(TEST_SCAN_DIR, tempfile.gettempdir())

    assert is_tarfile(
        os.path.join(
            tempfile.gettempdir(), '.'.join(
                (os.path.basename(file_io.resolve_path_end(TEST_SCAN_DIR)),
                 'pupyl'))))
예제 #12
0
def test_scan_directory():
    """
    Unit test for scan method, directory case
    """
    file_io = FileIO()

    test_against_tree = [
        abspath(f'{TEST_SCAN_DIR}{ffile}')
        for ffile in [*walk(TEST_SCAN_DIR)][0][-1]
    ]

    test_current_tree = [*file_io.scan(abspath(TEST_SCAN_DIR))]

    assert test_current_tree == test_against_tree
예제 #13
0
def test_bind():
    """Unit test for method bind."""
    file_io = FileIO()

    file_io.dump(TEST_SCAN_DIR, tempfile.gettempdir())

    file_io.bind(
        os.path.join(
            tempfile.gettempdir(), '.'.join(
                (os.path.basename(file_io.resolve_path_end(TEST_SCAN_DIR)),
                 'pupyl'))), os.path.join(tempfile.gettempdir(),
                                          TEST_SCAN_DIR))

    assert os.path.isdir(os.path.join(tempfile.gettempdir(), TEST_SCAN_DIR))
예제 #14
0
def test_infer_file_type_tar_files():
    """Unit test for method infer_file_type_from_uri, tar file case."""
    file_io = FileIO()

    for ffile in os.listdir(TEST_TAR_LOCATION):
        test_file_type = mimetypes.guess_type(
            os.path.join(TEST_TAR_LOCATION, ffile))[1]

        assert file_io.infer_file_type_from_uri(
            os.path.join(TEST_TAR_LOCATION, ffile),
            mimetype=True) == TarCompressedTypes.mime(test_file_type)

        assert file_io.infer_file_type_from_uri(
            os.path.join(TEST_TAR_LOCATION, ffile),
            mimetype=False) == TarCompressedTypes.name(test_file_type)
예제 #15
0
def test_scan_compressed_tar_file_local():
    """Unit test for method scan_compressed_tar_file, local case."""
    test_tar_compressed_file_readers = {
        'TZ2': 'r:bz2',
        'TGZ': 'r:gz',
        'TXZ': 'r:xz'
    }

    file_io = FileIO()

    for ffile in os.listdir(TEST_TAR_LOCATION):
        test_file_type = mimetypes.guess_type(
            os.path.join(TEST_TAR_LOCATION, ffile))[1]

        for dfile in file_io.scan_compressed_tar_file(
                os.path.join(TEST_TAR_LOCATION, ffile),
                test_tar_compressed_file_readers[TarCompressedTypes.name(
                    test_file_type)]):
            assert os.path.exists(dfile)
예제 #16
0
    def test_scan_file(self):
        """ Unit test for scan method, file case."""
        file_io = FileIO()

        with self.assertRaises(FileScanNotPossible):
            assert next(file_io.scan(TEST_LOCAL)) == TEST_LOCAL
예제 #17
0
    def test_infer_file_type_from_uri_unknown(self):
        """ Unit test infer_file_type_from_uri, unknown case. """
        with self.assertRaises(FileTypeNotSupportedYet):
            file_io = FileIO()

            file_io.infer_file_type_from_uri(TEST_UNKNOWN)