From 77297dec3d40ece36fbc19ac38b72855b93b55e4 Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Sun, 12 Nov 2023 08:31:47 -0800 Subject: [PATCH] Fix relative root-dir always erroring --- doc/changes/+a76d448e.bugfix | 1 + src/autogqlschema/_directive.py | 2 +- tests/test_integration.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 doc/changes/+a76d448e.bugfix diff --git a/doc/changes/+a76d448e.bugfix b/doc/changes/+a76d448e.bugfix new file mode 100644 index 0000000..5548310 --- /dev/null +++ b/doc/changes/+a76d448e.bugfix @@ -0,0 +1 @@ +Fix relative root directories always erroring \ No newline at end of file diff --git a/src/autogqlschema/_directive.py b/src/autogqlschema/_directive.py index f980027..1e0f55d 100644 --- a/src/autogqlschema/_directive.py +++ b/src/autogqlschema/_directive.py @@ -75,7 +75,7 @@ def run(self) -> list[Node]: root_dir = self.options.get("root-dir") if root_dir: root_dir = pathlib.Path(root_dir) - if not root_dir.is_absolute: + if not root_dir.is_absolute(): root_dir = pathlib.Path(self.env.app.confdir) / root_dir else: root_dir = self.env.app.confdir diff --git a/tests/test_integration.py b/tests/test_integration.py index 02d1aad..04ca8a8 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -460,3 +460,42 @@ def test_role(self, soup: bs4.BeautifulSoup): assert len(links) == 1 link = links[0] assert link.get_text() == "schema1.union1" + + +class TestRootDir: + @pytest.fixture(scope="class") + def soup(self, tmp_path_factory): + cwd = pathlib.Path.cwd() + root_dir = "schema" + + test_name = "type_objects" + dest = tmp_path_factory.mktemp(test_name) + (dest / root_dir).mkdir() + test_file_name = f"{test_name}.graphql" + test_file = pathlib.Path("tests") / "fixtures" / test_file_name + shutil.copy(test_file, dest / root_dir) + shutil.copy(pathlib.Path("tests") / "fixtures" / "conf.py", dest) + + with (dest / "index.rst").open("w") as out_f: + out_f.write(f"Schema\n") + out_f.write(f"------\n") + out_f.write(f"\n") + out_f.write(f".. autogqlschema:: schema1\n") + out_f.write(f" :debug:\n") + out_f.write(f" :root-dir: {root_dir}\n") + out_f.write(f" :source-files: {test_file_name}\n\n") + + os.chdir(dest) + rebuild() + + with (pathlib.Path("_build") / "html" / "index.html").open() as in_f: + yield bs4.BeautifulSoup(in_f, "html.parser") + + os.chdir(cwd) + + def test_simple_parse(self, soup: bs4.BeautifulSoup): + sig = soup.find(id="schema1.type1") + assert signature_text(sig) == "type type1" + + sig = soup.find(id="schema1.type1.field1") + assert signature_text(sig) == "field1: Int"