def _get_file( self, src_path: str, dst_path: str, ): r"""Get file from backend.""" audfactory.download(src_path, dst_path, verbose=False)
def test_create(params, expected_columns): # Create a new lookup table url = audfactory.Lookup.create( SERVER, REPOSITORY, GROUP_ID, VERSION, params, ) # Raise error if lookup table exists already with pytest.raises(RuntimeError): audfactory.Lookup.create( SERVER, REPOSITORY, GROUP_ID, VERSION, params, ) # Check content of CSV file lookup_file = audfactory.download(url) with open(lookup_file, newline='') as csvfile: reader = csv.reader(csvfile, delimiter=',') assert next(reader) == expected_columns # Clean up os.remove(lookup_file) audfactory.Lookup.delete(SERVER, REPOSITORY, GROUP_ID, VERSION)
def test_columns_ids_table(lookup_table): assert lookup_table.table == [['id']] assert lookup_table.columns == [] assert lookup_table.ids == [] params = {'a': 1, 'b': 2.0, 'c': '3.0.0', 'd': True, 'e': 4.0, 'f': None} lookup_table.extend(list(params.keys())) lookup_table.append(params) csvfile = audfactory.download(lookup_table.url) df = pd.read_csv(csvfile) # Replace nan by None df['f'] = None os.remove(csvfile) table = lookup_table.table assert list(df.columns.values) == table[0] assert list(df.iloc[0, :].values) == table[1] assert lookup_table.columns == table[0][1:] assert lookup_table.ids == [table[1][0]] with pytest.raises(AttributeError): lookup_table.table = []
def test_download( tmpdir, url, destination, force_download, expected_path, ): cache = str(tmpdir.mkdir('audfactory')) destination = audeer.safe_path( os.path.join(cache, destination) ) path = audfactory.download( url, destination, chunk=4 * 1024, force_download=force_download, verbose=False, ) assert os.path.exists(path) assert os.path.basename(path) == expected_path
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
def test_checksum(tmpdir): with pytest.raises(RuntimeError, match=r'File not found:'): audfactory.checksum('file-not-found.txt') with pytest.raises(RuntimeError, match=r'File not found:'): url = f'{SERVER}/{REPOSITORY}/file-not-found.txt' audfactory.checksum(url) url = ( f'{SERVER}/{REPOSITORY}/{GROUP_ID_URL}/' f'{NAME}/{VERSION}/{FILENAME}.zip' ) cache = str(tmpdir.mkdir('audfactory')) destination = audeer.safe_path(cache) path = audfactory.download(url, destination) assert audfactory.checksum(url, type='md5') == \ audfactory.checksum(path, type='md5') assert audfactory.checksum(url, type='sha1') == \ audfactory.checksum(path, type='sha1') assert audfactory.checksum(url, type='sha256') == \ audfactory.checksum(path, type='sha256')