Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Commit 8c658f1

Browse files
committed
v1.7.4
1 parent c049c2e commit 8c658f1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
55

66
## [Unreleased]
77

8-
<!-- None < 2022-09-29 11:34:08+00:00 -->
8+
## [1.7.4] - 2022-10-02
9+
10+
- [[#57](https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/pull/57)] Cache TerraformTest methods ([marshall7m](https://github.com/marshall7m)) <!-- 2022-10-02 16:38:46+00:00 -->
911

1012
## [1.7.3] - 2022-09-29
1113
<!-- 2022-09-29 11:34:08+00:00 < 2022-09-15 05:29:49+00:00 -->
@@ -160,7 +162,8 @@ All notable changes to this project will be documented in this file.
160162
<!-- 2019-09-10 06:58:18+00:00 < None -->
161163

162164
<!-- markdown-link-check-disable -->
163-
[Unreleased]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.3...HEAD
165+
[Unreleased]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.4...HEAD
166+
[1.7.4]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.3...v1.7.4
164167
[1.7.3]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.2...v1.7.3
165168
[1.7.2]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.1...v1.7.2
166169
[1.7.1]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.0...v1.7.1

tftest.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from hashlib import sha1
4444
import inspect
4545

46-
__version__ = '1.7.3'
46+
__version__ = '1.7.4'
4747

4848
_LOGGER = logging.getLogger('tftest')
4949

@@ -315,7 +315,8 @@ class TerraformTest(object):
315315
the directory of the python file that instantiates this class
316316
"""
317317

318-
def __init__(self, tfdir, basedir=None, binary='terraform', env=None, enable_cache=False, cache_dir=None):
318+
def __init__(self, tfdir, basedir=None, binary='terraform', env=None,
319+
enable_cache=False, cache_dir=None):
319320
"""Set Terraform folder to operate on, and optional base directory."""
320321
self._basedir = basedir or os.getcwd()
321322
self.binary = binary
@@ -376,6 +377,7 @@ def _abspath(self, path):
376377
return path if os.path.isabs(path) else os.path.join(self._basedir, path)
377378

378379
def _cache(func):
380+
379381
def cache(self, **kwargs):
380382
"""
381383
Runs the tftest instance method or retreives the cache value if it exists
@@ -399,8 +401,7 @@ def cache(self, **kwargs):
399401

400402
params = {
401403
**{
402-
k: v
403-
for k, v in self.__dict__.items()
404+
k: v for k, v in self.__dict__.items()
404405
# only uses instance attributes that are involved in the results of
405406
# the decorated method
406407
if k in ["binary", "_basedir", "tfdir", "env"]
@@ -409,8 +410,8 @@ def cache(self, **kwargs):
409410
}
410411

411412
hash_filename = sha1(
412-
json.dumps(params, sort_keys=True, default=str).encode("cp037")
413-
).hexdigest() + ".pickle"
413+
json.dumps(params, sort_keys=True,
414+
default=str).encode("cp037")).hexdigest() + ".pickle"
414415

415416
cache_key = cache_dir / hash_filename
416417
_LOGGER.debug("Cache key: %s", cache_key)
@@ -437,6 +438,7 @@ def cache(self, **kwargs):
437438
pickle.dump(out, f, pickle.HIGHEST_PROTOCOL)
438439

439440
return out
441+
440442
return cache
441443

442444
@_cache
@@ -596,7 +598,8 @@ def apply(self, input=False, color=False, auto_approve=True, tf_vars=None,
596598
return self.execute_command('apply', *cmd_args).out
597599

598600
@_cache
599-
def output(self, name=None, color=False, json_format=True, use_cache=False, **kw):
601+
def output(self, name=None, color=False, json_format=True, use_cache=False,
602+
**kw):
600603
"""Run Terraform output command."""
601604
cmd_args = []
602605
if name:
@@ -715,8 +718,8 @@ def __init__(self, tfdir, basedir=None, binary='terragrunt', env=None,
715718
cache_dir: optional base directory to use for caching, defaults to
716719
the directory of the python file that instantiates this class
717720
"""
718-
TerraformTest.__init__(self, tfdir, basedir, binary,
719-
env, enable_cache, cache_dir)
721+
TerraformTest.__init__(self, tfdir, basedir, binary, env, enable_cache,
722+
cache_dir)
720723
self.tg_run_all = tg_run_all
721724
if self.tg_run_all:
722725
self._plan_formatter = partial(_parse_run_all_out,

0 commit comments

Comments
 (0)