Skip to content

Commit 87ed6cd

Browse files
test for infer_type
1 parent f98ff99 commit 87ed6cd

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

acclimatise/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,14 @@ def infer_type(string) -> typing.Optional[cli_types.CliType]:
395395
elif file_re.match(string):
396396
if input_re.match(string) and not output_re.match(string):
397397
return cli_types.CliFile(output=False)
398-
elif not input_re.match(string) and output_re.match(string):
398+
elif not input_re.match(string) and output_re.match(string):
399399
return cli_types.CliFile(output=True)
400400
else:
401401
return cli_types.CliFile()
402402
elif dir_re.match(string):
403403
if input_re.match(string) and not output_re.match(string):
404404
return cli_types.CliDir(output=False)
405-
elif not input_re.match(string) and output_re.match(string):
405+
elif not input_re.match(string) and output_re.match(string):
406406
return cli_types.CliDir(output=True)
407407
else:
408408
return cli_types.CliDir()

test/test_type_inference.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from acclimatise.cli_types import CliString
2+
from acclimatise.model import infer_type
3+
4+
5+
def test_type_inference():
6+
test_strings = [("", CliString, False), ("int", CliInteger, False),
7+
("size", CliInteger, False), ("length", CliInteger, False),
8+
("max", CliInteger, False), ("min", CliInteger, False),
9+
("str", CliString, False), ("float", CliFloat, False),
10+
("decimal", CliFloat, False), ("bool", CliBoolean, False),
11+
("file", CliFile, False), ("path", CliFile, False),
12+
("input file", CliFile, False),
13+
("output file", CliFile, True), ("folder", CliDir, False),
14+
("directory", CliDir, False),
15+
("output directory", CliDir, False)]
16+
17+
for ts in test_strings:
18+
typ = infer_type(ts[0])
19+
assert isinstance(typ, ts[1]), "%s should be %s but is %s" % (ts[0], ts[1], typ)
20+
assert not typ.hasattr("output") or typ.output == ts[2]

0 commit comments

Comments
 (0)