Beispiel #1
0
    def test_default_install_location(self):
        """Verify that pushes to the default local install location work as expected"""
        with patch('quilt3.Package._materialize') as materialize_mock:
            pkg_name = 'Quilt/nice-name'
            Package.install(pkg_name, registry='s3://my-test-bucket')

            materialize_mock.assert_called_once_with(
                quilt3.util.get_install_location().rstrip('/') + '/' +
                pkg_name, )
Beispiel #2
0
    def test_verify(self):
        pkg = Package()

        pkg.set('foo', b'Hello, World!')
        pkg.build('quilt/test')

        Package.install('quilt/test', LOCAL_REGISTRY, dest='test')
        assert pkg.verify('test')

        Path('test/blah').write_text('123')
        assert not pkg.verify('test')
        assert pkg.verify('test', extra_files_ok=True)

        Path('test/foo').write_text('123')
        assert not pkg.verify('test')
        assert not pkg.verify('test', extra_files_ok=True)

        Path('test/foo').write_text('Hello, World!')
        Path('test/blah').unlink()
        assert pkg.verify('test')
Beispiel #3
0
def download_test_resources(args: Args):
    # Try running the download pipeline
    try:
        # Get test resources dir
        resources_dir = (Path(__file__).parent.parent / "napari_aicsimageio" /
                         "tests" / "resources").resolve()
        resources_dir.mkdir(exist_ok=True)

        # Use or read top hash
        if args.top_hash is None:
            with open(Path(__file__).parent / "TEST_RESOURCES_HASH.txt",
                      "r") as f:
                top_hash = f.readline().rstrip()
        else:
            top_hash = args.top_hash

        log.info(f"Downloading test resources using top hash: {top_hash}")

        # Get quilt package
        Package.install(
            "aicsimageio/test_resources",
            "s3://aics-modeling-packages-test-resources",
            dest=resources_dir,
            top_hash=top_hash,
            path="resources",
        )

        log.info(f"Completed package download.")

    # Catch any exception
    except Exception as e:
        log.error("=============================================")
        if args.debug:
            log.error("\n\n" + traceback.format_exc())
            log.error("=============================================")
        log.error("\n\n" + str(e) + "\n")
        log.error("=============================================")
        sys.exit(1)
Beispiel #4
0
    def test_install(self):
        # Manifest

        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO(b'abcdef'),
            },
            expected_params={
                'Bucket': 'my-test-bucket',
                'Key': '.quilt/named_packages/Quilt/Foo/latest',
            }
        )

        self.s3_stubber.add_response(
            method='head_object',
            service_response={
                'VersionId': 'v1',
                'ContentLength': REMOTE_MANIFEST.stat().st_size,
            },
            expected_params={
                'Bucket': 'my-test-bucket',
                'Key': '.quilt/packages/abcdef',
            }
        )

        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO(REMOTE_MANIFEST.read_bytes()),
                'ContentLength': REMOTE_MANIFEST.stat().st_size,
            },
            expected_params={
                'Bucket': 'my-test-bucket',
                'Key': '.quilt/packages/abcdef',
            }
        )

        # Objects

        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO(b'a,b,c'),
            },
            expected_params={
                'Bucket': 'my_bucket',
                'Key': 'my_data_pkg/bar.csv',
            }
        )

        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO(b'Hello World!'),
            },
            expected_params={
                'Bucket': 'my_bucket',
                'Key': 'my_data_pkg/baz/bat',
            }
        )

        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO('💩'.encode()),
            },
            expected_params={
                'Bucket': 'my_bucket',
                'Key': 'my_data_pkg/foo',
            }
        )

        with patch('quilt3.data_transfer.s3_transfer_config.max_request_concurrency', 1):
            Package.install('Quilt/Foo', registry='s3://my-test-bucket', dest='package')

        p = Package.browse('Quilt/Foo')

        assert p['foo'].get() == 's3://my_bucket/my_data_pkg/foo'

        # Check that the cache works.
        local_path = pathlib.Path(p['foo'].get_cached_path())
        assert local_path == pathlib.Path.cwd() / 'package/foo'
        assert local_path.read_text('utf8') == '💩'

        # Test that get_bytes and get_as_text works
        assert p['foo'].get_bytes().decode("utf-8") == '💩'
        assert p['foo'].get_as_string() == '💩'

        # Check that moving the file invalidates the cache...
        local_path.rename('foo2')
        assert p['foo'].get_cached_path() is None

        # ...but moving it back fixes it.
        pathlib.Path('foo2').rename(local_path)
        assert p['foo'].get_cached_path() == str(local_path)

        # Check that changing the contents invalidates the cache.
        local_path.write_text('omg')
        assert p['foo'].get_cached_path() is None

        # Check that installing the package again reuses the cached manifest and two objects - but not "foo".
        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO(b'abcdef'),
            },
            expected_params={
                'Bucket': 'my-test-bucket',
                'Key': '.quilt/named_packages/Quilt/Foo/latest',
            }
        )
        self.s3_stubber.add_response(
            method='get_object',
            service_response={
                'VersionId': 'v1',
                'Body': BytesIO('💩'.encode()),
            },
            expected_params={
                'Bucket': 'my_bucket',
                'Key': 'my_data_pkg/foo',
            }
        )

        with patch('quilt3.data_transfer.s3_transfer_config.max_request_concurrency', 1):
            Package.install('Quilt/Foo', registry='s3://my-test-bucket', dest='package/')