Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientForwardRefs test clients not in fixture and tests not working #314

Open
bombsimon opened this issue Sep 15, 2024 · 0 comments · May be fixed by #330
Open

ClientForwardRefs test clients not in fixture and tests not working #314

bombsimon opened this issue Sep 15, 2024 · 0 comments · May be fixed by #330

Comments

@bombsimon
Copy link
Contributor

The test test_main_generates_correct_package in tests/main/test_main.py requires manual adding of clients to be tested. This seems to have been forgotten when ClientForwardRefs was added.

I tried to just blindly add it to the fixture but this actually seems to uncover a bug where relative paths aren't resolved properly. With the following diff:

diff --git a/tests/main/test_main.py b/tests/main/test_main.py
index 3cf9f1d..84da31d 100644
--- a/tests/main/test_main.py
+++ b/tests/main/test_main.py
@@ -213,6 +213,30 @@ def test_main_shows_version():
             "example_client",
             CLIENTS_PATH / "custom_sync_query_builder" / "expected_client",
         ),
+        (
+            (
+                CLIENTS_PATH / "client_forward_refs" / "pyproject.toml",
+                (
+                    CLIENTS_PATH / "client_forward_refs" / "queries.graphql",
+                    CLIENTS_PATH / "client_forward_refs" / "schema.graphql",
+                    CLIENTS_PATH / "client_forward_refs" / "custom_scalars.py",
+                ),
+            ),
+            "client_forward_refs",
+            CLIENTS_PATH / "client_forward_refs" / "expected_client",
+        ),
+        (
+            (
+                CLIENTS_PATH / "client_forward_refs_shorter_results" / "pyproject.toml",
+                (
+                    CLIENTS_PATH / "client_forward_refs_shorter_results" / "queries.graphql",
+                    CLIENTS_PATH / "client_forward_refs_shorter_results" / "schema.graphql",
+                    CLIENTS_PATH / "client_forward_refs_shorter_results" / "custom_scalars.py",
+                ),
+            ),
+            "client_forward_refs_shorter_results",
+            CLIENTS_PATH / "client_forward_refs_shorter_results" / "expected_client",
+        ),
     ],
     indirect=["project_dir"],
 )

The result is as follows:

› pytest ./tests/main -k test_main_generates_correct_package -vv
[...]
test_main.py::test_main_generates_correct_package[project_dir14-client_forward_refs-expected_package_path14] FAILED        [ 93%]
test_main.py::test_main_generates_correct_package[project_dir15-client_forward_refs_shorter_results-expected_package_path15] FAILED [100%]

[...]
E           AssertionError: client.py
E           assert 'from typing ...ap_fragment\n' == 'from typing ...ap_fragment\n'
E
E             - from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, List, Optional, Union
E             ?                    ---------------
E             + from typing import Any, AsyncIterator, Dict, List, Optional, Union
E
E               from .async_base_client import AsyncBaseClient
E             + from .typing import TYPE_CHECKING...
E
E             ...Full output truncated (351 lines hidden), use '-vv' to show

[...]

        async def list_strings_1(self, **kwargs: Any) -> Optional[List[Optional[str]]]:
  -         from .list_strings_1 import ListStrings1
  +         from ..list_strings_1 import ListStrings1
  ?              +

[...]

/home/xxx/ariadne-codegen/tests/main/test_main.py:49: AssertionError
bombsimon added a commit to bombsimon/ariadne-codegen that referenced this issue Dec 25, 2024
- Add missing tests for `ClientForwardRefsPlugin` with and without
  combining with `ShorterResultsPlugin`.
- Fix faulty imports
  - Store name and level separate to allow dots specified either on the
    module or via level. When importing just lookup what level and name
    to use.
  - Always use level 0 for `TYPE_CHECKING_MODULE`.

Fixes mirumee#314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant