Skip to content

Commit 54b5915

Browse files
authored
Merge pull request #336 from jdkandersson/enhancement/support-int
Enhancement/support int
2 parents 308f2fe + 50b1c20 commit 54b5915

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add support for `int` values for `number` types.
13+
1014
## [v2.4.2] - 2021-04-04
1115

1216
### Added

open_alchemy/utility_base/from_dict/simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def convert(
3535
)
3636
return value
3737
if type_ == "number":
38-
if not isinstance(value, float):
38+
if not isinstance(value, (float, int)):
3939
raise exceptions.InvalidInstanceError(
4040
"Number type columns must have float values."
4141
)

tests/open_alchemy/utility_base/from_dict/test_simple.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,37 @@
1212
@pytest.mark.parametrize(
1313
"schema, value, exception",
1414
[
15-
({}, mock.MagicMock(), exceptions.TypeMissingError),
16-
({"type": "type 1"}, mock.MagicMock(), exceptions.FeatureNotImplementedError),
17-
({"type": "integer"}, 1.1, exceptions.InvalidInstanceError),
18-
({"type": "number"}, 1, exceptions.InvalidInstanceError),
19-
({"type": "string"}, 1, exceptions.InvalidInstanceError),
20-
({"type": "boolean"}, 1, exceptions.InvalidInstanceError),
21-
],
22-
ids=[
23-
"no type",
24-
"unsupported type",
25-
"integer different type",
26-
"number different type",
27-
"string different type",
28-
"boolean different type",
15+
pytest.param({}, mock.MagicMock(), exceptions.TypeMissingError, id="no type"),
16+
pytest.param(
17+
{"type": "type 1"},
18+
mock.MagicMock(),
19+
exceptions.FeatureNotImplementedError,
20+
id="unsupported type",
21+
),
22+
pytest.param(
23+
{"type": "integer"},
24+
1.1,
25+
exceptions.InvalidInstanceError,
26+
id="integer different type",
27+
),
28+
pytest.param(
29+
{"type": "number"},
30+
"1",
31+
exceptions.InvalidInstanceError,
32+
id="number different type",
33+
),
34+
pytest.param(
35+
{"type": "string"},
36+
1,
37+
exceptions.InvalidInstanceError,
38+
id="string different type",
39+
),
40+
pytest.param(
41+
{"type": "boolean"},
42+
1,
43+
exceptions.InvalidInstanceError,
44+
id="boolean different type",
45+
),
2946
],
3047
)
3148
@pytest.mark.utility_base
@@ -66,6 +83,12 @@ def test_convert_invalid(schema, value, exception):
6683
1.1,
6784
id="number",
6885
),
86+
pytest.param(
87+
{"type": "number"},
88+
1,
89+
1,
90+
id="number integer value",
91+
),
6992
pytest.param(
7093
{"type": "number", "format": "float"},
7194
1.1,

0 commit comments

Comments
 (0)