Пример #1
0
 def _exists(
     self,
     path: str,
 ) -> bool:
     r"""Check if file exists on backend."""
     try:
         # Can lead to RuntimeError: 404 page not found
         return audfactory.path(path).exists()
     except RuntimeError:  # pragma: nocover
         return False
Пример #2
0
def cleanup():
    url = audfactory.url(
        pytest.SERVER,
        group_id=pytest.GROUP_ID,
        repository=pytest.REPOSITORY,
    )
    path = audfactory.path(url)
    if path.exists():
        path.rmdir()
    cleanup_files = [
        'db-1.1.0.yaml',
    ]
    for file in cleanup_files:
        if os.path.exists(file):
            os.remove(file)
Пример #3
0
def cleanup_session():
    path = os.path.join(
        pytest.ROOT,
        '..',
        '.coverage.*',
    )
    for file in glob.glob(path):
        os.remove(file)
    yield
    if os.path.exists(pytest.ROOT):
        shutil.rmtree(pytest.ROOT)
    url = audfactory.path(
        audfactory.url(
            pytest.ARTIFACTORY_HOST,
            repository=pytest.REPOSITORY_NAME,
            group_id=pytest.ID,
        ), )
    if url.exists():
        url.unlink()
Пример #4
0
def test_deploy(filename, content, expected_versions):
    # Use random name to ensure parallel running
    # Remove existing path to trigger new creation
    url = audfactory.url(
        SERVER,
        group_id=GROUP_ID,
        repository=REPOSITORY,
        name=NAME,
        version=VERSION,
    )
    # Add version to filename
    name, ext = os.path.splitext(os.path.basename(filename))
    url = f'{url}/{name}-{VERSION}{ext}'
    # create local file
    if filename != 'file-not-found.txt':
        with open(filename, 'w') as fp:
            fp.write(content)
    # upload artifact
    returned_url = audfactory.deploy(filename, url)
    # clean up
    os.remove(filename)
    # check url
    assert url == returned_url
    assert audfactory.path(url).exists()

    # download artifact
    path = audfactory.download(url, filename)
    # check content
    with open(path, 'r') as fp:
        lines = [line.strip() for line in fp.readlines()]
        assert content == '\n'.join(lines)
    # clean up
    os.remove(path)
    # check version
    versions = audfactory.versions(
        SERVER,
        REPOSITORY,
        GROUP_ID,
        NAME,
    )
    assert expected_versions == versions
Пример #5
0
 def _glob(
     self,
     pattern: str,
     folder: typing.Optional[str],
 ) -> typing.List[str]:
     r"""Return matching files names."""
     if folder is not None:
         group_id = audfactory.path_to_group_id(folder)
     else:
         group_id = None
     url = audfactory.url(
         self.host,
         repository=self.repository,
         group_id=group_id,
     )
     path = audfactory.path(url)
     try:
         result = [str(x) for x in path.glob(pattern)]
     except RuntimeError:  # pragma: no cover
         result = []
     return result
Пример #6
0
def fixture_publish_artifact():
    url = audfactory.url(
        SERVER,
        repository=REPOSITORY,
        group_id=GROUP_ID,
        name=NAME,
        version=VERSION,
    )
    path = audfactory.path(url)
    if path.exists():
        path.unlink()
    # create local file
    with open(f'{FILENAME}.txt', 'w') as fp:
        fp.write(CONTENT)
    audeer.create_archive('.', f'{FILENAME}.txt', f'{FILENAME}.zip')
    # upload artifact
    url = f'{url}/{FILENAME}.zip'
    audfactory.deploy(f'{FILENAME}.zip', url)
    # clean up
    os.remove(f'{FILENAME}.txt')
    os.remove(f'{FILENAME}.zip')
Пример #7
0
 def _remove_file(
     self,
     path: str,
 ):
     r"""Remove file from backend."""
     audfactory.path(path).unlink()
Пример #8
0
def test_path(url, expected_urls):
    path = audfactory.path(url)
    urls = [str(u) for u in path]
    assert expected_urls == urls