Skip to content

Commit c29a8c1

Browse files
change subclassing
1 parent f3305d3 commit c29a8c1

2 files changed

Lines changed: 29 additions & 33 deletions

File tree

acclimatise/cli_types.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,28 @@ class CliBoolean(CliType):
7474

7575

7676
@dataclass(unsafe_hash=True)
77-
class CliDir(CliType):
77+
class CliFileSystemType(CliType):
7878
"""
79-
Takes a directory path
79+
Takes a directory / file path
8080
"""
8181

82-
pass
83-
84-
85-
@dataclass(unsafe_hash=True)
86-
class CliOutputDir(CliType):
82+
output: bool = None
8783
"""
88-
Takes a directory path
84+
Indicator if it is input or output (None if unknown)
8985
"""
9086

91-
pass
92-
9387

9488
@dataclass(unsafe_hash=True)
95-
class CliFile(CliType):
89+
class CliDir(CliFileSystemType):
9690
"""
97-
Takes a file path
91+
Takes a directory path
9892
"""
9993

10094
pass
10195

10296

10397
@dataclass(unsafe_hash=True)
104-
class CliOutputFile(CliType):
98+
class CliFile(CliFileSystemType):
10599
"""
106100
Takes a file path
107101
"""

test/test_type_inference.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55

66

77
@pytest.mark.parametrize(
8-
"string,typ",
9-
[("", CliString),
10-
("int", CliInteger),
11-
("size", CliInteger),
12-
("length", CliInteger),
13-
("max", CliInteger),
14-
("min", CliInteger),
15-
("str", CliString),
16-
("float", CliFloat),
17-
("decimal", CliFloat),
18-
("bool", CliBoolean),
19-
("file", CliFile),
20-
("path", CliFile),
21-
("input file", CliFile),
22-
("output file", CliOutputFile),
23-
("folder", CliDir),
24-
("directory", CliDir),
25-
("output directory", CliOutputDir)])
26-
def test_type_inference(string, typ):
27-
assert isinstance(infer_type(string), typ)
8+
"string,typ,isoutput",
9+
[("", CliString, False),
10+
("int", CliInteger, False),
11+
("size", CliInteger, False),
12+
("length", CliInteger, False),
13+
("max", CliInteger, False),
14+
("min", CliInteger, False),
15+
("str", CliString, False),
16+
("float", CliFloat, False),
17+
("decimal", CliFloat, False),
18+
("bool", CliBoolean, False),
19+
("file", CliFile, False),
20+
("path", CliFile, False),
21+
("input file", CliFile, False),
22+
("output file", CliFile, True),
23+
("folder", CliDir, False),
24+
("directory", CliDir, False),
25+
("output directory", CliDir, True)])
26+
def test_type_inference(string, typ, isoutput):
27+
inferred_type = infer_type(string)
28+
assert isinstance(inferred_type, typ)
29+
assert not hasattr(inferred_type, "output") or inferred_type.output == isoutput

0 commit comments

Comments
 (0)