Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonmeso committed Feb 8, 2024
1 parent 2ba0c58 commit 918dc4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions giza/commands/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def download(
if version.status != VersionStatus.COMPLETED:
raise ValueError(f"Model version status is not completed {version.status}")

echo("Transpilation is ready, downloading! ✅")
echo("Data is ready, downloading! ✅")
downloads: Dict[str, bytes] = client.download(
model_id,
version.version,
Expand All @@ -287,7 +287,7 @@ def download(
download_model_or_sierra(content, output_path, name)
except zipfile.BadZipFile as zip_error:
raise ValueError(
"Something went wrong with the transpiled file", zip_error.args[0]
"Something went wrong with the download", zip_error.args[0]
) from None
echo(f"{name} saved at: {output_path}")
except ValueError as e:
Expand Down
31 changes: 16 additions & 15 deletions tests/commands/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def return_content():
tmp = BytesIO()
with zipfile.ZipFile(tmp, mode="w", compression=zipfile.ZIP_DEFLATED) as f:
f.writestr("file1.txt", "hi")
return tmp.getvalue()
return {"model": tmp.getvalue()}

models = ModelList(
__root__=[
Expand Down Expand Up @@ -168,7 +168,8 @@ def return_content():
# Called twice, once to open the model and second to write the zip
mock_open.assert_called()
assert "Reading model from path" in result.stdout
assert "Transpilation recieved" in result.stdout
assert "Downloading model" in result.stdout
assert "model saved at" in result.stdout
assert result.exit_code == 0


Expand All @@ -190,10 +191,10 @@ def test_versions_transpile_http_error(tmpdir):
assert result.exit_code == 1


# Test version transpilation with bad zip file
def test_versions_transpile_bad_zip(tmpdir):
# Test version transpilation with file
def test_versions_transpile_file(tmpdir):
def return_content():
return b"some bytes"
return {"model": b"some bytes"}

models = ModelList(
__root__=[
Expand Down Expand Up @@ -240,9 +241,9 @@ def return_content():

# Called twice, once to open the model and second to write the zip
mock_open.assert_called()
assert "Something went wrong" in result.stdout
assert "Error ->" in result.stdout
assert result.exit_code == 1
assert "Transpilation is fully compatible" in result.stdout
assert "Downloading model" in result.stdout
assert result.exit_code == 0


# Test successful version download
Expand All @@ -260,7 +261,7 @@ def return_content():
tmp = BytesIO()
with zipfile.ZipFile(tmp, mode="w", compression=zipfile.ZIP_DEFLATED) as f:
f.writestr("file1.txt", "hi")
return tmp.getvalue()
return {"model": tmp.getvalue()}

with patch.object(VersionsClient, "get", return_value=version), patch.object(
VersionsClient, "download", return_value=return_content()
Expand All @@ -281,7 +282,7 @@ def return_content():
)

mock_open.assert_called()
assert "Transpilation is ready, downloading!" in result.stdout
assert "Data is ready, downloading!" in result.stdout
assert result.exit_code == 0


Expand All @@ -308,8 +309,8 @@ def test_versions_download_server_error():
assert "Error at download" in result.stdout


# Test version download with bad zip file
def test_versions_download_bad_zip(tmpdir):
# Test version download but a file, imitating a sierra file
def test_versions_download_file(tmpdir):
version = Version(
version=1,
size=1,
Expand All @@ -320,7 +321,7 @@ def test_versions_download_bad_zip(tmpdir):
)

def return_content():
return b"some bytes"
return {"model": b"some bytes"}

with patch.object(VersionsClient, "get", return_value=version), patch.object(
VersionsClient, "download", return_value=return_content()
Expand All @@ -339,8 +340,8 @@ def return_content():
expected_error=True,
)

assert "Something went wrong with the transpiled file" in result.stdout
assert result.exit_code == 1
assert "saved at" in result.stdout
assert result.exit_code == 0


# Test version download with missing model_id and version_id
Expand Down

0 comments on commit 918dc4e

Please sign in to comment.