Skip to content

Commit

Permalink
Fix relative root-dir always erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
AWhetter committed Nov 12, 2023
1 parent 1e0cf8e commit 77297de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changes/+a76d448e.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix relative root directories always erroring
2 changes: 1 addition & 1 deletion src/autogqlschema/_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 77297de

Please sign in to comment.