Skip to content

Commit

Permalink
Update tests and CI\CD
Browse files Browse the repository at this point in the history
  • Loading branch information
yar-kik committed Dec 11, 2022
1 parent ed5df2c commit 486e042
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ script:
- mypy app_properties/
- coverage run --source=app_properties -m pytest && coveralls
- coverage report --fail-under=80

deploy:
provider: pypi
username: "__token__"
password: $PYPI_API_TOKEN
on:
tags: true
2 changes: 1 addition & 1 deletion app_properties/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .main import properties

__all__ = ("properties",)
__version__ = "1.1.0"
__version__ = "1.1.1"
4 changes: 4 additions & 0 deletions tests/test_type_converter/test_dataclass_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def class_with_dataclasses_fixt():
class MainClass:
dataclass_var: TestClass
dataclass_field_class: DataclassFieldClass
wrong_dataclass_var: TestClass

return MainClass

Expand All @@ -40,3 +41,6 @@ def test_field_is_dataclass(class_with_dataclasses_fixt):
assert not hasattr(
class_with_dataclasses_fixt.dataclass_field_class, "init_false_var"
)
assert class_with_dataclasses_fixt.wrong_dataclass_var == TestClass(
int_var=0, list_var=[]
)
39 changes: 37 additions & 2 deletions tests/test_type_converter/test_primitive_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,52 @@ class CastPrimitiveClass(BaseClass):
return CastPrimitiveClass


@pytest.fixture
def fields_not_presented_fixt():
@properties(filename="types_cast.yml", root="primitive")
class DefaultFieldClass:
default_int_var: int
default_float_var: float
default_str_var: str
default_bool_var: bool
default_none_var: None

return DefaultFieldClass


def test_not_cast_vars(not_cast_primitive_class_fixt):
assert not_cast_primitive_class_fixt.int_var == "10"
assert not_cast_primitive_class_fixt.float_var == "10.5"
assert not_cast_primitive_class_fixt.bool_var == True
assert not_cast_primitive_class_fixt.none_var == None
assert not_cast_primitive_class_fixt.none_var is None
assert not_cast_primitive_class_fixt.str_var == "str"


def test_cast_vars(cast_primitive_class_fixt):
assert cast_primitive_class_fixt.int_var == 10
assert cast_primitive_class_fixt.float_var == 10.5
assert cast_primitive_class_fixt.bool_var == True
assert cast_primitive_class_fixt.none_var == None
assert cast_primitive_class_fixt.none_var is None
assert cast_primitive_class_fixt.str_var == "str"


def test_default_fields(fields_not_presented_fixt):
assert fields_not_presented_fixt.default_none_var is None
assert fields_not_presented_fixt.default_str_var == ""
assert fields_not_presented_fixt.default_bool_var == False
assert fields_not_presented_fixt.default_int_var == 0
assert fields_not_presented_fixt.default_float_var == 0.0


def test_wrong_type_casting():
with pytest.raises(ValueError):

@properties(filename="types_cast.yml", root="primitive")
class WrongIntClass:
wrong_int_var: int

with pytest.raises(ValueError):

@properties(filename="types_cast.yml", root="primitive")
class WrongFloatClass:
wrong_float_var: float
3 changes: 3 additions & 0 deletions tests/test_type_converter/types_cast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ primitive:
bool_var: true
none_var: null
str_var: "str"
wrong_int_var: 10_wrong_int
wrong_float_var: 10,5

tuple:
keyword_named_tuple_var:
Expand Down Expand Up @@ -134,6 +136,7 @@ dataclass:
default_factory_var:
- 16
- 18
wrong_dataclass_var:

base:
list_var:
Expand Down
20 changes: 10 additions & 10 deletions tests/test_using/test_override_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


class DefaultVar:
list_var: list = []
dict_var: dict = {}
int_var: int = 0
float_var: float = 0.0
list_var: list = ["x", "y"]
dict_var: dict = {"k": "v"}
int_var: int = 5
float_var: float = 3.4
bool_var: bool = False
none_var: None = None
str_var: str = ""
str_var: str = "some var"


@properties(filename="application.yml", override_default=True)
Expand All @@ -23,12 +23,12 @@ class AllowDefault(DefaultVar):

def test_allow_default_vars():
assert AllowDefault.bool_var == False
assert AllowDefault.dict_var == {}
assert AllowDefault.list_var == []
assert AllowDefault.int_var == 0
assert AllowDefault.float_var == 0.0
assert AllowDefault.dict_var == {"k": "v"}
assert AllowDefault.list_var == ["x", "y"]
assert AllowDefault.int_var == 5
assert AllowDefault.float_var == 3.4
assert AllowDefault.none_var is None
assert AllowDefault.str_var == ""
assert AllowDefault.str_var == "some var"


def test_override_default_vars():
Expand Down

0 comments on commit 486e042

Please sign in to comment.