Skip to content

Commit

Permalink
v1.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoo committed Oct 2, 2022
1 parent c049c2e commit 8c658f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

<!-- None < 2022-09-29 11:34:08+00:00 -->
## [1.7.4] - 2022-10-02

- [[#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 -->

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

<!-- markdown-link-check-disable -->
[Unreleased]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.3...HEAD
[Unreleased]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.4...HEAD
[1.7.4]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.3...v1.7.4
[1.7.3]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.2...v1.7.3
[1.7.2]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.1...v1.7.2
[1.7.1]: https://github.com/GoogleCloudPlatform/terraform-python-testing-helper/compare/v1.7.0...v1.7.1
Expand Down
21 changes: 12 additions & 9 deletions tftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from hashlib import sha1
import inspect

__version__ = '1.7.3'
__version__ = '1.7.4'

_LOGGER = logging.getLogger('tftest')

Expand Down Expand Up @@ -315,7 +315,8 @@ class TerraformTest(object):
the directory of the python file that instantiates this class
"""

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

def _cache(func):

def cache(self, **kwargs):
"""
Runs the tftest instance method or retreives the cache value if it exists
Expand All @@ -399,8 +401,7 @@ def cache(self, **kwargs):

params = {
**{
k: v
for k, v in self.__dict__.items()
k: v for k, v in self.__dict__.items()
# only uses instance attributes that are involved in the results of
# the decorated method
if k in ["binary", "_basedir", "tfdir", "env"]
Expand All @@ -409,8 +410,8 @@ def cache(self, **kwargs):
}

hash_filename = sha1(
json.dumps(params, sort_keys=True, default=str).encode("cp037")
).hexdigest() + ".pickle"
json.dumps(params, sort_keys=True,
default=str).encode("cp037")).hexdigest() + ".pickle"

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

return out

return cache

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

@_cache
def output(self, name=None, color=False, json_format=True, use_cache=False, **kw):
def output(self, name=None, color=False, json_format=True, use_cache=False,
**kw):
"""Run Terraform output command."""
cmd_args = []
if name:
Expand Down Expand Up @@ -715,8 +718,8 @@ def __init__(self, tfdir, basedir=None, binary='terragrunt', env=None,
cache_dir: optional base directory to use for caching, defaults to
the directory of the python file that instantiates this class
"""
TerraformTest.__init__(self, tfdir, basedir, binary,
env, enable_cache, cache_dir)
TerraformTest.__init__(self, tfdir, basedir, binary, env, enable_cache,
cache_dir)
self.tg_run_all = tg_run_all
if self.tg_run_all:
self._plan_formatter = partial(_parse_run_all_out,
Expand Down

0 comments on commit 8c658f1

Please sign in to comment.