Skip to content

Commit

Permalink
Fix tautology
Browse files Browse the repository at this point in the history
The parentheses in the asserts in test_envVars and test_updateTrue were being interpreted as a set(!), making them always evaluate to True. This was resulting in these tests passing when there was actually something wrong with them.
- Asserts fixed to evaluate correctly
- Tests fixed to pass fair and square even with the corrected assertions
  • Loading branch information
garlic-os committed Jul 18, 2024
1 parent 2a34802 commit 089a769
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions test/credentials/test_envVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ def test_envVars(
rc_path = rc_path.expanduser()
rc_path.unlink(missing_ok=True)

# Give the rc file mock contents
rc_path.write_text(template.format(uid=random_string(), key=random_string()))

test_uid = random_string()
test_key = random_string()

with monkeypatch.context() as mp:
mp.setenv(env_var_name_uid, test_uid)
mp.setenv(env_var_name_key, test_key)
credentials.check_api(model_name, None, None, './', update_rc_file=False)
credentials.check_api(model_name, None, None, './', update_rc_file=True)

expected_content = template.format(uid=test_uid, key=test_key)
actual_content = rc_path.read_text()
rc_path.unlink()

assert (
expected_content == actual_content,
f'{rc_path} was not updated correctly'
)
assert expected_content == actual_content, f'{rc_path} was not created correctly'
11 changes: 6 additions & 5 deletions test/credentials/test_updateTrue.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ def test_updateTrue(model_name, template):
return
rc_path = Path('./') / (hidden_ext + rc_filename)

# Give the rc file mock contents
rc_path.write_text(template.format(uid=random_string(), key=random_string()))

# Use check_api to update the rc file
test_uid = random_string()
test_key = random_string()
credentials.check_api(model_name, test_uid, test_key, './', update_rc_file=True)

# Check that the rc file was properly updated
expected_content = template.format(uid=test_uid, key=test_key)
actual_content = rc_path.read_text()
rc_path.unlink()

assert (
expected_content == actual_content,
f'{rc_path} was not updated correctly'
)
assert expected_content == actual_content, f'{rc_path} was not updated correctly'
2 changes: 1 addition & 1 deletion tools/RAiDER/models/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def check_api(model: str,
# one that belongs to this URL.
import netrc
rc_path.touch()
netrc_credentials = netrc.netrc(rc_path)
netrc_credentials = netrc.netrc(rc_path.name)
netrc_credentials.hosts[url] = (uid, None, key)
rc_path.write_text(str(netrc_credentials))
rc_path.chmod(0o000600)
Expand Down

0 comments on commit 089a769

Please sign in to comment.