Skip to content

Commit

Permalink
add tests for inferring iterables & string-to-bool
Browse files Browse the repository at this point in the history
  • Loading branch information
dhpitt committed Mar 15, 2024
1 parent 5f8553e commit 41310c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/configmypy/tests/test_argparse_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


TEST_CONFIG_DICT = {
'default': {'opt': {'optimizer': 'adam', 'lr': 0.1},
'data': {'dataset': 'ns', 'batch_size': 12}},
'default': {'opt': {'optimizer': 'adam', 'lr': 0.1, 'regularizer': True},
'data': {'dataset': 'ns', 'batch_size': 12, 'test_resolutions':[16,32]}},
'test': {'opt': {'optimizer': 'SGD'}}
}

Expand All @@ -17,12 +17,21 @@ def test_ArgparseConfig(monkeypatch):
config.data.batch_size = 24
assert config == args
assert kwargs == {}

monkeypatch.setattr("sys.argv", ['test', '--data.batch_size', '24', '--config_name', 'test'])

# test ability to infer None and iterables
monkeypatch.setattr("sys.argv", ['test', '--data.batch_size', '24',\
'--data.test_resolutions', '[8, None]',
'--opt.regularizer', 'False',
'--config_name', 'test'])
config = Bunch(TEST_CONFIG_DICT['default'])
parser = ArgparseConfig(infer_types=True, config_name=None)
args, kwargs = parser.read_conf(config)
config.data.batch_size = 24
assert args.data.test_resolutions == [8, None]
assert not args.opt.regularizer #boolean False, not 'False'

args.data.test_resolutions = [16,32]
args.opt.regularizer = True
assert config == args
assert kwargs == Bunch(dict(config_name='test'))

Expand Down
1 change: 0 additions & 1 deletion src/configmypy/type_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def __call__(self, var):
var: original variable (any type)
"""
print(f"{self.orig_type=} {var=}")
if self.orig_type == bool:
return infer_boolean(var, self.strict)
elif self.orig_type == float or self.orig_type == int:
Expand Down

0 comments on commit 41310c8

Please sign in to comment.