Skip to content

Commit

Permalink
Use separate test file for working dir test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoesters committed May 16, 2024
1 parent d2ab895 commit 5d04499
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
11 changes: 3 additions & 8 deletions tests/data/jsons/sys-prefix.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
"-c",
"import sys; f = open(r'__OUTPUT_FILE__', 'w'); f.write(sys.prefix); f.close()"
],
"description": "Note how __OUTPUT_FILE__ is using raw-strings. Otherwise the backslashes are not properly escaped.",
"working_dir": "%TEMP%/working_dir_test"
"description": "Note how __OUTPUT_FILE__ is using raw-strings. Otherwise the backslashes are not properly escaped."
},
"linux": {
"precommand": "export TMP=/tmp",
"working_dir": "${HOME}/working_dir_test"
},
"linux": {},
"osx": {
"CFBundleName": "Sys Prefix",
"working_dir": "${TMPDIR}/working_dir_test"
"CFBundleName": "Sys Prefix"
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions tests/data/jsons/working-dir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://schemas.conda.io/menuinst-1.schema.json",
"menu_name": "Sys.Prefix {{ DISTRIBUTION_NAME }}",
"menu_items": [
{
"name": "Sys.Prefix",
"description": "This will install to Windows and Linux with default options. MacOS has a custom option.",
"icon": null,
"command": [
"{{ PYTHON }}",
"-c",
"import sys; print(sys.prefix)"
],
"platforms": {
"win": {
"command": [
"{{ PYTHON }}",
"-c",
"import sys; f = open(r'__OUTPUT_FILE__', 'w'); f.write(sys.prefix); f.close()"
],
"description": "Note how __OUTPUT_FILE__ is using raw-strings. Otherwise the backslashes are not properly escaped.",
"working_dir": "%TEMP%/working_dir_test"
},
"linux": {
"working_dir": "${TMP}/working_dir_test"
},
"osx": {
"CFBundleName": "Sys Prefix",
"working_dir": "${TMPDIR}/working_dir_test"
}
}
}
]
}
6 changes: 4 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,17 @@ def test_name_dictionary(target_env_is_base):
remove(abs_json_path, target_prefix=tmp_target_path, base_prefix=tmp_base_path)


def test_vars_in_working_dir(tmp_path, delete_files):
def test_vars_in_working_dir(tmp_path, monkeypatch, delete_files):
if PLATFORM == "win":
expected_directory = Path(os.environ["TEMP"], "working_dir_test")
elif PLATFORM == "osx":
expected_directory = Path(os.environ["TMPDIR"], "working_dir_test")
else:
# Linux often does not have an environment variable for the tmp directory
monkeypatch.setenv("TMP", "/tmp")
expected_directory = Path("/tmp/working_dir_test")
delete_files.append(expected_directory)
datafile = str(DATA / "jsons" / "sys-prefix.json")
datafile = str(DATA / "jsons" / "working-dir.json")
try:
install(datafile, base_prefix=tmp_path, target_prefix=tmp_path)
assert expected_directory.exists()
Expand Down

0 comments on commit 5d04499

Please sign in to comment.