Skip to content

Commit 9f4a173

Browse files
committed
lint and justfile target
1 parent 4f2a681 commit 9f4a173

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

justfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
lint:
4+
pre-commit run --all-files
5+
6+
test:
7+
pytest -v tests/unit

tests/unit/conftest.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,43 @@
44
import boto3
55
import jsonschema
66
import pytest
7-
import logging
87

98

109
@pytest.fixture()
1110
def validator():
12-
1311
def schema_validate(translator, resource):
14-
schema_path = f'schema.{translator.tf_type}.json'
12+
schema_path = f"schema.{translator.tf_type}.json"
1513
schema = load_data(schema_path)
1614
if schema is None:
17-
cfn = boto3.client('cloudformation')
18-
rtype = cfn.describe_type(
19-
TypeName=translator.cfn_type, Type='RESOURCE')
20-
schema = json.loads(rtype['Schema'])
21-
(Path(__file__).parent / "data" / schema_path).write_text(json.dumps(schema, indent=2))
15+
cfn = boto3.client("cloudformation")
16+
rtype = cfn.describe_type(TypeName=translator.cfn_type, Type="RESOURCE")
17+
schema = json.loads(rtype["Schema"])
18+
(Path(__file__).parent / "data" / schema_path).write_text(
19+
json.dumps(schema, indent=2)
20+
)
2221

2322
props = set(resource)
2423
sprops = set(schema["properties"].keys())
2524
unknown = props.difference(sprops)
2625
if unknown:
27-
raise KeyError("unknown resource keys %s" % (', '.join(unknown)))
26+
raise KeyError("unknown resource keys %s" % (", ".join(unknown)))
2827

2928
validator = jsonschema.Draft7Validator(schema)
30-
29+
3130
errors = list(validator.iter_errors(resource))
3231
if errors:
33-
print(
34-
"%s errors %d" % (translator.cfn_type, len(errors))
35-
)
32+
print("%s errors %d" % (translator.cfn_type, len(errors)))
3633

3734
for e in errors:
38-
print("Resource %s error:\n %s" % (translator.cfn_type, str(e)))
35+
print("Resource %s error:\n %s" % (translator.cfn_type, str(e)))
3936

4037
if errors:
4138
raise ValueError(
42-
f"resource type {translator.cfn_type} had translation errors")
39+
f"resource type {translator.cfn_type} had translation errors"
40+
)
4341

4442
return schema_validate
4543

46-
47-
4844

4945
def load_data(filename):
5046
path = Path(__file__).parent / "data" / filename

tests/unit/test_resources.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
21
from conftest import load_data
32
from tfdevops.cli import Translator
43

54

65
def test_elasticache_replication_group(validator):
76

8-
translator = Translator.get_translator('elasticache_replication_group')()
9-
resource = load_data('elasticache.json')
7+
translator = Translator.get_translator("elasticache_replication_group")()
8+
resource = load_data("elasticache.json")
109
props = translator.get_properties(resource)
1110
validator(translator, props)
12-
13-

tfdevops/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ def validate(template):
377377
help="S3 Bucket and Prefix (s3://bucket/pre/fix) for oversized templates and resources",
378378
)
379379
@click.option(
380-
"--state-file",
381-
help="Terraform state file - output of terraform show -json",
380+
"--state-file", help="Terraform state file - output of terraform show -json",
382381
)
383382
@click.option("--types", multiple=True, help="Only consider these terraform types")
384383
def cfn(module, template, resources, types, s3_path, state_file):

0 commit comments

Comments
 (0)