Repository: Materials-Consortia/optimade-python-tools
Pull request #1849 (2023-11-05 17:44:59)

Add test that checks whether client can find at least one base URL
This has potential to be flaky if the providers list is down, but think that is a slim chance and this would have caught the previous issue in #1848.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) Report
> Merging [#1849](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) (edf65c8) into [master](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/commit/2970d9a583ffcd96336053f8fe963dd3ba36785d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) (2970d9a) will **increase** coverage by `0.69%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master    #1849      +/-   ##
==========================================
+ Coverage   90.53%   91.22%   +0.69%     
==========================================
  Files          75       75              
  Lines        4627     4629       +2     
==========================================
+ Hits         4189     4223      +34     
+ Misses        438      406      -32     
```

| [Flag](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) | Coverage Δ | |
|---|---|---|
| [project](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) | `91.22% <100.00%> (+0.69%)` | :arrow_up: |
| [validator](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) | `90.68% <100.00%> (+0.69%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Files](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia) | Coverage Δ | |
|---|---|---|
| [optimade/client/client.py](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia#diff-b3B0aW1hZGUvY2xpZW50L2NsaWVudC5weQ==) | `87.14% <ø> (-0.05%)` | :arrow_down: |
| [optimade/utils.py](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia#diff-b3B0aW1hZGUvdXRpbHMucHk=) | `91.20% <100.00%> (+35.52%)` | :arrow_up: |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/1849/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Materials-Consortia)



Patch:
diff --git a/optimade/client/client.py b/optimade/client/client.py
index b7b2a105..1f7e1294 100644
--- a/optimade/client/client.py
+++ b/optimade/client/client.py
@@ -200,7 +200,6 @@ class OptimadeClient:
                     progress=progress,
                 )
             )
-            print(self.base_urls)
         else:
             if exclude_providers or include_providers or exclude_databases:
                 raise RuntimeError(
diff --git a/optimade/utils.py b/optimade/utils.py
index d48ea395..cf7222db 100644
--- a/optimade/utils.py
+++ b/optimade/utils.py
@@ -190,6 +190,9 @@ def get_all_databases(
         )
     else:
         progress = contextlib.nullcontext()
+        progress.print = lambda _: None  # type: ignore[attr-defined]
+        progress.advance = lambda *_: None  # type: ignore[attr-defined]
+        _task = None
 
     with progress:
         for provider in get_providers():


Test patch:
diff --git a/tests/server/routers/test_utils.py b/tests/server/routers/test_utils.py
index 9fe2c203..fec7236b 100644
--- a/tests/server/routers/test_utils.py
+++ b/tests/server/routers/test_utils.py
@@ -35,6 +35,9 @@ def mocked_providers_list_response(
         def json(self) -> Union[list, dict]:
             return self.data
 
+        def content(self) -> str:
+            return str(self.data)
+
     return MockResponse(providers, 200)
 
 
@@ -73,6 +76,12 @@ def test_get_providers():
             assert get_providers() == providers_list
 
 
+def test_get_all_databases():
+    from optimade.utils import get_all_databases
+
+    assert list(get_all_databases())
+
+
 def test_get_providers_warning(caplog, top_dir):
     """Make sure a warning is logged as a last resort."""
     import copy