From 195f334796fb13d5adfec3c8afb5c80f5f8a9478 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Tue, 31 Mar 2026 07:39:51 +0000 Subject: [PATCH 1/3] Fix: preserve absolute Path object for tfdir - Ensure `_abspath` returns the original `Path` object when it's absolute, reverting the modernization regression. - Cast `self.tfdir` to `str` before encoding to prevent `AttributeError` when cache is enabled. - Add test cases to verify both behaviors. --- test/test_tfdir_path.py | 17 +++++++++++++++++ tftest.py | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/test_tfdir_path.py diff --git a/test/test_tfdir_path.py b/test/test_tfdir_path.py new file mode 100644 index 0000000..c83d424 --- /dev/null +++ b/test/test_tfdir_path.py @@ -0,0 +1,17 @@ +import tempfile +from pathlib import Path +import tftest + +def test_tfdir_as_path(): + with tempfile.TemporaryDirectory() as tmpdir: + tmpdir_path = Path(tmpdir).resolve() + tf = tftest.TerraformTest(tmpdir_path) + # The regression: tf.tfdir / 'something' throws TypeError + # if tf.tfdir is converted to a string. + assert (tf.tfdir / 'something') == tmpdir_path / 'something' + +def test_tfdir_as_str(): + with tempfile.TemporaryDirectory() as tmpdir: + tf = tftest.TerraformTest(tmpdir) + assert isinstance(tf.tfdir, str) + diff --git a/tftest.py b/tftest.py index e8fd718..3ada96b 100644 --- a/tftest.py +++ b/tftest.py @@ -349,7 +349,7 @@ def _abspath(self, path): """Make relative path absolute from base dir.""" path_obj = Path(path) if path_obj.is_absolute(): - return str(path_obj) + return path return str(Path(self._basedir) / path) def _dirhash(self, directory, hash, ignore_hidden=False, @@ -429,7 +429,7 @@ def cache(self, **kwargs): return func(self, **kwargs) cache_dir = self.cache_dir / \ - Path(sha1(self.tfdir.encode("cp037")).hexdigest()) / \ + Path(sha1(str(self.tfdir).encode("cp037")).hexdigest()) / \ Path(func.__name__) cache_dir.mkdir(parents=True, exist_ok=True) From 87480f590dc4e7f76223411737c00c08755a93ae Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Tue, 31 Mar 2026 07:44:25 +0000 Subject: [PATCH 2/3] Chore: add missing license boilerplate to new files --- .github/workflows/publish-pypi.yml | 14 ++++++++++++++ test/test_tfdir_path.py | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 696934e..f195aac 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -1,3 +1,17 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Publish to PyPI on: diff --git a/test/test_tfdir_path.py b/test/test_tfdir_path.py index c83d424..bf9123a 100644 --- a/test/test_tfdir_path.py +++ b/test/test_tfdir_path.py @@ -1,7 +1,22 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import tempfile from pathlib import Path import tftest + def test_tfdir_as_path(): with tempfile.TemporaryDirectory() as tmpdir: tmpdir_path = Path(tmpdir).resolve() @@ -10,8 +25,8 @@ def test_tfdir_as_path(): # if tf.tfdir is converted to a string. assert (tf.tfdir / 'something') == tmpdir_path / 'something' + def test_tfdir_as_str(): with tempfile.TemporaryDirectory() as tmpdir: tf = tftest.TerraformTest(tmpdir) assert isinstance(tf.tfdir, str) - From 4fdcaac796cf36914c51a30b6f549297ac5688d9 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Tue, 31 Mar 2026 07:47:10 +0000 Subject: [PATCH 3/3] Chore: add GEMINI.md with CLI instructions --- GEMINI.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 GEMINI.md diff --git a/GEMINI.md b/GEMINI.md new file mode 100644 index 0000000..67b9af1 --- /dev/null +++ b/GEMINI.md @@ -0,0 +1,7 @@ +# Gemini CLI Instructions for terraform-python-testing-helper + +- **Git Workflow:** Never use `git commit --amend`. Always create a new commit and push to the same branch to update an existing Pull Request. +- **File Editing:** Always use the `replace` tool (or `write_file` for new files) for file edits. Do NOT use shell heredocs (`cat << 'EOF'`) or inline Python scripts to modify files. +- **Copyright Boilerplate:** All new files must include the Apache 2.0 license boilerplate at the top. Ensure the copyright year is current (e.g., 2026). +- **Linting:** Always run the project's linters before committing changes. Specifically, check formatting with `yapf --diff --recursive --parallel *.py test` and verify license headers with `python3 .github/workflows/scripts/check_boilerplate.py .`. +- **Regressions & Testing:** When fixing a regression, fix it at the source library level. Do not modify the caller's code to work around the issue. Always create a reliable test case that reproduces the error before implementing the fix. \ No newline at end of file