Skip to content

Commit 317aef4

Browse files
committed
Added tests for check_toml
Also assures we print filename when error occurs.
1 parent 8d7d40c commit 317aef4

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pre_commit_hooks/check_toml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
1919
with open(filename) as f:
2020
toml.load(f)
2121
except toml.TomlDecodeError as exc:
22-
print(exc)
22+
print('{}: {}'.format(filename, exc))
2323
retval = 1
2424
return retval
2525

tests/check_toml_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from __future__ import absolute_import
2+
from __future__ import unicode_literals
3+
4+
from pre_commit_hooks.check_toml import main
5+
6+
7+
def test_toml_good(tmpdir):
8+
filename = tmpdir.join('f')
9+
filename.write("""
10+
key = # INVALID
11+
12+
= "no key name" # INVALID
13+
""")
14+
ret = main((filename.strpath,))
15+
assert ret == 1
16+
17+
18+
def test_toml_bad(tmpdir):
19+
filename = tmpdir.join('f')
20+
filename.write(
21+
"""
22+
# This is a TOML document.
23+
24+
title = "TOML Example"
25+
26+
[owner]
27+
name = "John"
28+
dob = 1979-05-27T07:32:00-08:00 # First class dates
29+
""",
30+
)
31+
ret = main((filename.strpath,))
32+
assert ret == 0

0 commit comments

Comments
 (0)