Skip to content

Commit

Permalink
Revert "update one test to with raises"
Browse files Browse the repository at this point in the history
This reverts commit cb2550e.
  • Loading branch information
ajberdy committed Oct 20, 2023
1 parent cb2550e commit 2f14ae9
Showing 1 changed file with 53 additions and 57 deletions.
110 changes: 53 additions & 57 deletions test/integ_tests/test_create_quantum_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,72 +198,68 @@ def test_completed_quantum_job(aws_session, capsys):
assert data in log_data


@pytest.mark.xfail(
(sys.version_info.major, sys.version_info.minor) != decorator_python_version,
raises=RuntimeError,
reason="Python version mismatch",
)
def test_decorator_job():
class MyClass:
attribute = "value"

def __str__(self):
return f"MyClass({self.attribute})"

define_job_contexts = (
pytest.raises(
RuntimeError, match="Python version must match between local environment and container."
)
if (sys.version_info.major, sys.version_info.minor) != decorator_python_version
else ()
@hybrid_job(
device=Devices.Amazon.SV1,
include_modules="job_test_script",
dependencies=str(Path("test", "integ_tests", "requirements.txt")),
input_data=str(Path("test", "integ_tests", "requirements")),
)
with define_job_contexts:
def decorator_job(a, b: int, c=0, d: float = 1.0, **extras):
save_job_result(job_test_script.job_helper())
with open(Path(get_input_data_dir()) / "requirements.txt", "r") as f:
assert f.readlines() == ["pytest\n"]
with open(Path("test", "integ_tests", "requirements.txt"), "r") as f:
assert f.readlines() == ["pytest\n"]
assert dir(pytest)
assert a.attribute == "value"
assert b == 2
assert c == 0
assert d == 5
assert extras["extra_arg"] == "extra_value"

hp_file = os.environ["AMZN_BRAKET_HP_FILE"]
with open(hp_file, "r") as f:
hyperparameters = json.load(f)
assert hyperparameters == {
"a": "MyClass{value}",
"b": "2",
"c": "0",
"d": "5",
"extra_arg": "extra_value",
}

with open("test/output_file.txt", "w") as f:
f.write("hello")

job = decorator_job(MyClass(), 2, d=5, extra_arg="extra_value")
assert job.result()["status"] == "SUCCESS"

@hybrid_job(
device=Devices.Amazon.SV1,
include_modules="job_test_script",
dependencies=str(Path("test", "integ_tests", "requirements.txt")),
input_data=str(Path("test", "integ_tests", "requirements")),
)
def decorator_job(a, b: int, c=0, d: float = 1.0, **extras):
save_job_result(job_test_script.job_helper())
with open(Path(get_input_data_dir()) / "requirements.txt", "r") as f:
assert f.readlines() == ["pytest\n"]
with open(Path("test", "integ_tests", "requirements.txt"), "r") as f:
assert f.readlines() == ["pytest\n"]
assert dir(pytest)
assert a.attribute == "value"
assert b == 2
assert c == 0
assert d == 5
assert extras["extra_arg"] == "extra_value"

hp_file = os.environ["AMZN_BRAKET_HP_FILE"]
with open(hp_file, "r") as f:
hyperparameters = json.load(f)
assert hyperparameters == {
"a": "MyClass{value}",
"b": "2",
"c": "0",
"d": "5",
"extra_arg": "extra_value",
}

with open("test/output_file.txt", "w") as f:
f.write("hello")

job = decorator_job(MyClass(), 2, d=5, extra_arg="extra_value")
assert job.result()["status"] == "SUCCESS"

current_dir = Path.cwd()
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
try:
job.download_result()
with open(Path(job.name, "test", "output_file.txt"), "r") as f:
assert f.read() == "hello"
assert (
Path(job.name, "results.json").exists()
and Path(job.name, "test").exists()
and not Path(job.name, "test", "integ_tests").exists()
)
finally:
os.chdir(current_dir)
current_dir = Path.cwd()
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
try:
job.download_result()
with open(Path(job.name, "test", "output_file.txt"), "r") as f:
assert f.read() == "hello"
assert (
Path(job.name, "results.json").exists()
and Path(job.name, "test").exists()
and not Path(job.name, "test", "integ_tests").exists()
)
finally:
os.chdir(current_dir)


@pytest.mark.xfail(
Expand Down

0 comments on commit 2f14ae9

Please sign in to comment.