Skip to content

Commit

Permalink
Fix windows tests failing due to ~ in directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jesszzzz committed Oct 25, 2024
1 parent 7ccf653 commit fa39a9f
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_python_run(self, tmpdir: str) -> None:
[
sys.executable,
"hydra_app/main.py",
f"hydra.run.dir={tmpdir}",
f'hydra.run.dir="{tmpdir}"',
"app.user=test_user",
]
)
Expand All @@ -26,7 +26,7 @@ def test_python_run(self, tmpdir: str) -> None:
def test_installed_run(self, tmpdir: str) -> None:
self.verify_output(
subprocess.check_output(
["hydra_app", f"hydra.run.dir={tmpdir}", "app.user=test_user"]
["hydra_app", f'hydra.run.dir="{tmpdir}"', "app.user=test_user"]
)
)

Expand Down
6 changes: 5 additions & 1 deletion hydra/test_utils/launcher_common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import copy
import os
import re
from pathlib import Path
from pathlib import Path, PureWindowsPath

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'PureWindowsPath' is not used.
from typing import Any, Callable, List, Optional, Set

from omegaconf import DictConfig, OmegaConf
Expand Down Expand Up @@ -657,6 +657,10 @@ def test_to_absolute_path_multirun(
cfg = OmegaConf.merge(task_launcher_cfg, task_config)
assert isinstance(cfg, DictConfig)
path = str(Path("/foo/bar").absolute())
# Hack to use the right drive on windows
if path.startswith("C:"):
path.replace("C:", "D:", 1)
print("jszhangasdf", path)
integration_test(
tmpdir=self.get_test_scratch_dir(tmpdir),
task_config=cfg,
Expand Down
2 changes: 1 addition & 1 deletion hydra/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __enter__(self) -> "TaskTestFunction":
self.temp_dir = tempfile.mkdtemp()
overrides = copy.deepcopy(self.overrides)
assert overrides is not None
overrides.append(f"hydra.run.dir={self.temp_dir}")
overrides.append(f'hydra.run.dir="{self.temp_dir}"')
self.job_ret = self.hydra.run(
config_name=self.config_name,
task_function=self,
Expand Down
12 changes: 6 additions & 6 deletions plugins/hydra_ax_sweeper/tests/test_ax_sweeper_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_ax_logging(tmpdir: Path, cmd_arg: str, expected_str: str) -> None:
cmd = [
"tests/apps/polynomial.py",
"-m",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"polynomial.x=interval(-5, -2)",
"polynomial.z=10",
Expand All @@ -239,7 +239,7 @@ def test_search_space_exhausted_exception(tmpdir: Path, cmd_args: List[str]) ->
cmd = [
"tests/apps/polynomial.py",
"-m",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.sweeper.ax_config.max_trials=2",
] + cmd_args
Expand All @@ -260,7 +260,7 @@ def test_search_space_with_constraint_metric(tmpdir: Path, cmd_args: List[str])
cmd = [
"tests/apps/polynomial_with_constraint.py",
"-m",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.sweeper.ax_config.max_trials=2",
] + cmd_args
Expand Down Expand Up @@ -294,7 +294,7 @@ def test_jobs_using_choice_between_lists(
cmd = [
"tests/apps/polynomial_with_list_coefficients.py",
"-m",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.sweeper.ax_config.max_trials=3",
] + [cmd_arg]
Expand Down Expand Up @@ -331,7 +331,7 @@ def test_jobs_using_choice_between_dicts(
cmd = [
"tests/apps/polynomial_with_dict_coefficients.py",
"-m",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.sweeper.ax_config.max_trials=3",
] + [cmd_arg]
Expand All @@ -345,7 +345,7 @@ def test_example_app(tmpdir: Path) -> None:
cmd = [
"example/banana.py",
"-m",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"banana.x=int(interval(-5, 5))",
"banana.y=interval(-5, 10.1)",
Expand Down
149 changes: 75 additions & 74 deletions tests/jupyter/%run_test.ipynb
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"db:\n",
" driver: mysql\n",
" user: omry\n",
" pass: secret\n",
"ui:\n",
" windows:\n",
" create_db: true\n",
" view: true\n",
"schema:\n",
" database: school\n",
" tables:\n",
" - name: students\n",
" fields:\n",
" - name: string\n",
" - class: int\n",
" - name: exams\n",
" fields:\n",
" - profession: string\n",
" - time: data\n",
" - class: int\n",
"\n"
]
"cell_type": "code",
"execution_count": 2,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"db:\n",
" driver: mysql\n",
" user: omry\n",
" pass: secret\n",
"ui:\n",
" windows:\n",
" create_db: true\n",
" view: true\n",
"schema:\n",
" database: school\n",
" tables:\n",
" - name: students\n",
" fields:\n",
" - name: string\n",
" - class: int\n",
" - name: exams\n",
" fields:\n",
" - profession: string\n",
" - time: data\n",
" - class: int\n",
"\n"
]
}
],
"source": [
"import tempfile\n",
"tmpdir = tempfile.mkdtemp()\n",
"%run ../../examples/tutorials/basic/your_first_hydra_app/6_composition/my_app.py hydra.run.dir=\"$tmpdir\" hydra.job.chdir=True"
]
}
],
"metadata": {
"fileHeader": "",
"fileUid": "e9902ae9-30ff-4d48-8526-cc3f8ca8e64c",
"isAdHoc": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
}
],
"source": [
"import tempfile\n",
"tmpdir = tempfile.mkdtemp()\n",
"%run ../../examples/tutorials/basic/your_first_hydra_app/6_composition/my_app.py hydra.run.dir=$tmpdir hydra.job.chdir=True"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}
3 changes: 3 additions & 0 deletions tests/test_apps/app_with_unicode_in_config/my_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import sys

from omegaconf import DictConfig, OmegaConf

import hydra


@hydra.main(version_base=None, config_path=".", config_name="config")
def my_app(cfg: DictConfig) -> None:
sys.stdout.reconfigure(encoding="utf-8")
print(OmegaConf.to_yaml(cfg))


Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic_sweeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_partial_failure(
"tests/test_apps/app_can_fail/my_app.py",
"--multirun",
"+divisor=1,0",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'",
]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_app_with_callbacks(
) -> None:
cmd = [
app_path,
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'",
"hydra.job_logging.formatters.simple.format='[JOB] %(message)s'",
Expand All @@ -120,7 +120,7 @@ def test_experimental_save_job_info_callback(tmpdir: Path, multirun: bool) -> No

cmd = [
app_path,
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.sweep.dir=" + str(tmpdir),
"hydra.job.chdir=True",
]
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_save_job_return_callback(tmpdir: Path, multirun: bool) -> None:
cmd = [
sys.executable,
app_path,
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.sweep.dir=" + str(tmpdir),
"hydra.job.chdir=True",
]
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_experimental_rerun(

cmd = [
app_path,
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.sweep.dir=" + str(tmpdir),
"hydra.job.chdir=False",
"hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_env_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_env_defaults(tmpdir: Path) -> None:
cmd = [
"tests/test_apps/custom_env_defaults/my_app.py",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
]
run_python_script(cmd)
2 changes: 1 addition & 1 deletion tests/test_examples/test_advanced_config_search_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_config_search_path(
) -> None:
cmd = [
"examples/advanced/config_search_path/my_app.py",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
]
cmd.extend(args)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_examples/test_advanced_package_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test_advanced_package_override_simple(tmpdir: Path) -> None:
cmd = [
"examples/advanced/package_overrides/simple.py",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
]
result, _err = run_python_script(cmd)
Expand All @@ -23,7 +23,7 @@ def test_advanced_package_override_simple(tmpdir: Path) -> None:
def test_advanced_package_override_two_packages(tmpdir: Path) -> None:
cmd = [
"examples/advanced/package_overrides/two_packages.py",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
]
result, _err = run_python_script(cmd)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples/test_basic_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_basic_sweep_example(
cmd = [
app_path,
"--multirun",
"hydra.run.dir=" + str(tmpdir),
f'hydra.run.dir="{str(tmpdir)}"',
"hydra.job.chdir=True",
"hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'",
"hydra.job_logging.formatters.simple.format='[JOB] %(message)s'",
Expand Down
Loading

0 comments on commit fa39a9f

Please sign in to comment.