Repository: facebookresearch/hydra
Pull request #329 (2019-12-20 09:27:39)

Update hydra_compose_example.py

facebook-github-bot: Hi hrchu! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at <https://code.facebook.com/cla>. **If you are contributing on behalf of someone else (eg your employer)**, the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at [cla@fb.com](mailto:cla@fb.com?subject=CLA%20for%20facebookresearch%2Fhydra%20%23329). Thanks!
omry: Oh dang, I missed it when I changed the API.
Thanks for fixing it.
There should be a unit test testing that example, can you add one in tests/test_tutorials.py ?

There should be similar tests there testing other examples.

Patch:
diff --git a/examples/advanced/ad_hoc_composition/hydra_compose_example.py b/examples/advanced/ad_hoc_composition/hydra_compose_example.py
index 58f640d2d8..f6cd6b2cc1 100644
--- a/examples/advanced/ad_hoc_composition/hydra_compose_example.py
+++ b/examples/advanced/ad_hoc_composition/hydra_compose_example.py
@@ -6,7 +6,7 @@ if __name__ == "__main__":
     # initialize the Hydra subsystem.
     # This is needed for apps that cannot have a standard @hydra.main() entry point
     initialize(
-        task_name="my_app", search_path_dir="conf", strict=True,
+        config_dir="conf", strict=True,
     )
 
     cfg = compose("config.yaml", overrides=["db=mysql", "db.user=${env:USER}"])
diff --git a/website/docs/advanced/hydra_compose.md b/website/docs/advanced/hydra_compose.md
index 8f0eb104c7..980cce7c13 100644
--- a/website/docs/advanced/hydra_compose.md
+++ b/website/docs/advanced/hydra_compose.md
@@ -7,6 +7,8 @@ sidebar_label: Experimental compose API
 Hydra 0.11.0 introduces a new experimental API for composing configuration via the `hydra.experimental.compose()` function.
 Prior to calling compose(), you have to initialize Hydra: This can be done by using the standard `@hydra.main()` or by calling `hydra.experimental.initialize()`.
 
+Here is an [example Jupyter notebook utilizing this API](https://github.com/facebookresearch/hydra/tree/master/examples/notebook).
+
 ### `hydra.experimental.compose()` example
 ```python
 from hydra.experimental import compose, initialize


Test patch:
diff --git a/tests/test_tutorials.py b/tests/test_tutorials.py
index e9e9017ad2..410f7c11fb 100644
--- a/tests/test_tutorials.py
+++ b/tests/test_tutorials.py
@@ -290,3 +290,42 @@ def test_specializing_config_example(task_runner):  # noqa: F811
             model=dict(num_layers=5, type="alexnet"),
         )
         verify_dir_outputs(task.job_ret, overrides=task.overrides)
+
+
+@pytest.mark.parametrize(
+    "args,expected",
+    [
+        (
+            [],
+            {
+                "db": {"driver": "mysql", "pass": "secret", "user": "${env:USER}"},
+                "ui": {"windows": {"create_db": True, "view": True}},
+                "schema": {
+                    "database": "school",
+                    "tables": [
+                        {
+                            "name": "students",
+                            "fields": [{"name": "string"}, {"class": "int"}],
+                        },
+                        {
+                            "name": "exams",
+                            "fields": [
+                                {"profession": "string"},
+                                {"time": "data"},
+                                {"class": "int"},
+                            ],
+                        },
+                    ],
+                },
+            },
+        ),
+    ],
+)
+def test_advanced_ad_hoc_composition(tmpdir, args, expected):
+    cmd = [
+        sys.executable,
+        "examples/advanced/ad_hoc_composition/hydra_compose_example.py",
+        "hydra.run.dir=" + str(tmpdir),
+    ]
+    result = subprocess.check_output(cmd)
+    assert OmegaConf.create(str(result.decode("utf-8"))) == OmegaConf.create(expected)