Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz1273327 committed Feb 24, 2021
1 parent 991a396 commit 45dfbb8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.4

+ 修复了`boolean`型参数必须使用命令行设置无效的问题

# 0.1.3

## bug修复
Expand Down
9 changes: 5 additions & 4 deletions schema_entry/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ def _parse_commandline_args_by_schema(self,
try:
if self.schema is not None and self.schema.get("properties") is not None:
if self.schema["properties"].get(key) is not None and self.schema["properties"][key]["type"] == "boolean":
if self.schema.get("required") is None:
value = None
else:
if key not in self.schema["required"]:
if value is False:
if self.schema.get("required") is None:
value = None
else:
if key not in self.schema["required"]:
value = None
except Exception as e:
warnings.warn(str(e))
finally:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = schema_entry
version = 0.1.3
version = 0.1.4
url = https://github.com/Python-Tools/schema_entry
author = hsz
author_email = [email protected]
Expand Down
26 changes: 26 additions & 0 deletions tests/test_entrypoint_without_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,32 @@ def test_load_not_required_boolean_cmd_config3(self) -> None:
"b_b": "1234"
})

def test_load_not_required_boolean_cmd_config4(self) -> None:
root = EntryPoint(
name="test_a",
schema={
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"a_a": {
"type": "boolean",
"default": False
},
"b_b": {
"type": "string",
"default": "1234"
}
},
"required": ["a_a"]
},
main=lambda a_a, b_b: None
)
root(["--a-a"])
self.assertDictEqual(root.config, {
"a_a": True,
"b_b": "1234"
})

def test_load_cmd_noflag_config(self) -> None:
root = EntryPoint(
name="test_a",
Expand Down

0 comments on commit 45dfbb8

Please sign in to comment.