Beispiel #1
0
    def test_container(self, ext, mod_name):
        pathname = os.path.abspath(
            os.path.join(os.path.dirname(__file__), self.base_path + ext))
        try:
            sample_data = np.fromfile(pathname, dtype=np.uint8)
        except OSError as e:
            pytest.skip(f"no source file {pathname}")
        else:
            container = guess_container(sample_data)
            assert container.decompression_order[
                0].compression_algorithm == mod_name

            output = "tmp." + os.path.basename(pathname)
            pathname = os.path.join(os.path.dirname(__file__), output)

            try:
                compressed = container.calc_packed_bytes()
            except errors.InvalidAlgorithm:
                if ext in read_only_compressors:
                    pytest.skip(
                        f"skipping {pathname} because can't compress {ext} yet"
                    )

            # compressed data may not be the same; don't really care as long as
            # it decompresses the same
            container2 = guess_container(compressed)
            assert np.array_equal(container._data, container2._data)
Beispiel #2
0
    def test_glob(self, pathname):
        sample_data = np.fromfile(pathname, dtype=np.uint8)
        container = guess_container(sample_data)
        container.guess_media_type()
        output = "tmp." + os.path.basename(pathname)
        pathname = os.path.join(os.path.dirname(__file__), output)

        try:
            compressed = container.calc_packed_bytes()
        except errors.InvalidAlgorithm as e:
            pytest.skip(f"skipping {pathname}: {e}")
        else:
            # compressed data may not be the same; don't really care as long as
            # it decompresses the same
            container2 = guess_container(compressed)
            assert np.array_equal(container._data, container2._data)
Beispiel #3
0
 def test_samples_dir(self, pathname):
     if ".tar" in pathname or ".zip" in pathname:
         pytest.skip(f"skipping collections for this test: {pathname}")
     print(f"checking {pathname}")
     sample_data = np.fromfile(pathname, dtype=np.uint8)
     container = guess_container(sample_data)
     container.guess_media_type()
     is_expected_media(container, pathname)
Beispiel #4
0
 def check(pathname):
     print(f"checking {pathname}")
     sample_data = np.fromfile(pathname, dtype=np.uint8)
     container = guess_container(sample_data)
     container.guess_media_type()
     container.guess_filesystem()
     print(container.media.filesystem)
     print(container.verbose_info)
Beispiel #5
0
 def test_samples_dir(self, pathname):
     if ".tar" in pathname or ".zip" in pathname:
         pytest.skip(
             f"skipping archive collections for this test: {pathname}")
     sample_data = np.fromfile(pathname, dtype=np.uint8)
     if len(sample_data) == 0:
         pytest.skip(
             f"skipping zero-length files for this test: {pathname}")
     container = guess_container(sample_data)
     container.guess_media_type()
     is_expected_media(container, pathname)
Beispiel #6
0
 def test_samples_dir(self, pathname):
     # wrapped, ext = os.path.splitext(pathname)
     # print(f"checking {pathname}")
     # sample_data = np.fromfile(pathname, dtype=np.uint8)
     # container = guess_container(sample_data)
     # if container.compression_algorithm != "no compression":
     #     _, ext = os.path.splitext(wrapped)
     # container.guess_media_type()
     # print(ext, ext_to_valid_types)
     # if ext in ext_to_valid_types:
     #     assert container.media.__class__ in ext_to_valid_types[ext]
     # else:
     #     assert container.media.__class__ == Media
     if ".tar" in pathname or ".zip" in pathname:
         pytest.skip(f"skipping collections for this test: {pathname}")
     print(f"checking {pathname}")
     sample_data = np.fromfile(pathname, dtype=np.uint8)
     container = guess_container(sample_data)
     container.guess_media_type()
     is_expected_media(container, pathname)