fix: parametrizeを利用したテストパターンの集約

This commit is contained in:
Y_SAKAI 2022-08-16 21:17:41 +09:00
parent 23e3412e42
commit 00cb7602f6

View File

@ -4,10 +4,17 @@ from src.util.dict_checker import DictChecker
class TestDictChecker:
def test_is_empty_no_value(self):
@pytest.mark.parametrize('test_data,expect', [
('', True),
(None, True),
('test_data', False),
])
def test_is_empty(self, test_data, expect):
"""
Cases:
辞書型データの対象のキーの値が''(空文字)の場合Trueが返る
1. 辞書型データの対象のキーの値が''(空文字)の場合Trueが返る
2. 辞書型データの対象のキーの値がNoneの場合Trueが返る
3. 辞書型データの対象のキーの値が存在する場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
@ -17,7 +24,7 @@ class TestDictChecker:
# Arranges
object_dict = {
"test_key": ""
"test_key": test_data
}
sut = DictChecker(object_dict)
@ -26,12 +33,23 @@ class TestDictChecker:
actual = sut.is_empty("test_key")
# Expects
assert actual is True
assert actual is expect
def test_is_empty_none(self):
@pytest.mark.parametrize('test_data,expect', [
([''], False),
([None], False),
(['test_value'], False),
([], True),
('test_value', False)
])
def test_is_list_empty(self, test_data, expect):
"""
Cases:
辞書型データの対象のキーの値がNoneの場合Trueが返る
1. 辞書型のデータの対象のキーのリストの値が''(空文字)の場合Falseが返る
2. 辞書型データの対象のキーのリストの値がNoneの場合Falseが返る
3. 辞書型データの対象のキーのリストの値が存在する場合Falseが返る
4. 辞書型データの対象のキーのリストの値が[]()の場合Trueが返る
5. 辞書型データの対象のキーの値に文字列が存在する場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
@ -41,57 +59,7 @@ class TestDictChecker:
# Arranges
object_dict = {
"test_key": None
}
sut = DictChecker(object_dict)
# Act
actual = sut.is_empty("test_key")
# Expects
assert actual is True
def test_is_empty_exist_value(self):
"""
Cases:
辞書型データの対象のキーの値が存在する場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": "test_value"
}
sut = DictChecker(object_dict)
# Act
actual = sut.is_empty("test_key")
# Expects
assert actual is False
def test_is_list_empty_no_value(self):
"""
Cases:
辞書型のデータの対象のキーのリストの値が''(空文字)の場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": [
""
]
"test_key": test_data
}
sut = DictChecker(object_dict)
@ -100,12 +68,19 @@ class TestDictChecker:
actual = sut.is_list_empty("test_key")
# Expects
assert actual is False
assert actual is expect
def test_is_list_empty_none(self):
@pytest.mark.parametrize('test_data,expect', [
({"test_key": "test_value"}, True),
({}, False),
({"test_key": ""}, False),
])
def test_check_key_exist(self, test_data, expect) -> bool:
"""
Cases:
辞書型データの対象のキーのリストの値がNoneの場合Falseが返る
1. 辞書型データの対象のキーが存在するかつ値が存在する場合Trueが返る
2. 辞書型データの対象のキーが存在しない場合Falseが返る
3. 辞書型データの対象のキーの値が存在しない場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
@ -114,109 +89,7 @@ class TestDictChecker:
"""
# Arranges
object_dict = {
"test_key": [
None
]
}
sut = DictChecker(object_dict)
# Act
actual = sut.is_list_empty("test_key")
# Expects
assert actual is False
def test_is_list_empty_blank(self):
"""
Cases:
辞書型データの対象のキーのリストの値が[]()の場合Trueが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": []
}
sut = DictChecker(object_dict)
# Act
actual = sut.is_list_empty("test_key")
# Expects
assert actual is True
def test_is_list_empty_exist_string(self):
"""
Cases:
辞書型データの対象のキーの値に文字列が存在する場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": "test_value"
}
sut = DictChecker(object_dict)
# Act
actual = sut.is_list_empty("test_key")
# Expects
assert actual is False
def test_is_list_empty_exist_value(self):
"""
Cases:
辞書型データの対象のキーのリストの値が存在する場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": [
"test_value"
]
}
sut = DictChecker(object_dict)
# Act
actual = sut.is_list_empty("test_key")
# Expects
assert actual is False
def test_check_key_exist(self) -> bool:
"""
Cases:
辞書型データの対象のキーが存在するかつ値が存在する場合Trueが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": "test_value"
}
object_dict = test_data
sut = DictChecker(object_dict)
@ -224,12 +97,17 @@ class TestDictChecker:
actual = sut.check_key_exist("test_key")
# Expects
assert actual is True
assert actual is expect
def test_check_key_exist_no_key(self) -> bool:
@pytest.mark.parametrize('test_data,test_type,expect', [
({"test_key": "test_value"}, str, True),
({"test_key": 1}, str, False)
])
def test_check_data_type(self, test_data, test_type, expect) -> bool:
"""
Cases:
辞書型データの対象のキーが存在しない場合Falseが返る
1. 辞書型データの対象のキーの値の型が指定した型と一致した場合Trueが返る
2. 辞書型データの対象のキーの値の型が指定した型と一致しない場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
@ -238,93 +116,25 @@ class TestDictChecker:
"""
# Arranges
object_dict = {
}
object_dict = test_data
sut = DictChecker(object_dict)
# Act
actual = sut.check_key_exist("test_key")
actual = sut.check_data_type("test_key", test_type)
# Expects
assert actual is False
assert actual is expect
def test_check_key_exist_no_value(self) -> bool:
@pytest.mark.parametrize('test_data,expect', [
({"test_key": "2022-08-01T10:00:00.000Z"}, True),
({"test_key": "test_value"}, False)
])
def test_check_match_pattern(self, test_data, expect) -> bool:
"""
Cases:
辞書型データの対象のキーの値が存在しない場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": ""
}
sut = DictChecker(object_dict)
# Act
actual = sut.check_key_exist("test_key")
# Expects
assert actual is False
def test_check_data_type(self) -> bool:
"""
Cases:
辞書型データの対象のキーの値の型が指定した型と一致した場合Trueが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": "test_value"
}
sut = DictChecker(object_dict)
# Act
actual = sut.check_data_type("test_key", str)
# Expects
assert actual is True
def test_check_data_type_other_type(self) -> bool:
"""
Cases:
辞書型データの対象のキーの値の型が指定した型と一致しない場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": 1
}
sut = DictChecker(object_dict)
# Act
actual = sut.check_data_type("test_key", str)
# Expects
assert actual is False
def test_check_match_pattern(self) -> bool:
"""
Cases:
辞書型データの対象のキーの値の型が指定した正規表現と一致した場合Trueが返る
1. 辞書型データの対象のキーの値の型が指定した正規表現と一致した場合Trueが返る
2. 辞書型データの対象のキーの値の型が指定した正規表現と一致しない場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
@ -334,9 +144,7 @@ class TestDictChecker:
"""
# Arranges
object_dict = {
"test_key": "2022-08-01T10:00:00.000Z"
}
object_dict = test_data
sut = DictChecker(object_dict)
@ -346,34 +154,7 @@ class TestDictChecker:
actual = sut.check_match_pattern(pattern, "test_key")
# Expects
assert actual is True
def test_check_match_pattern_not_match(self) -> bool:
"""
Cases:
辞書型データの対象のキーの値の型が指定した正規表現と一致しない場合Falseが返る
Arranges:
- 辞書型のオブジェクト情報を準備する
- 辞書型チェックインスタンスを生成する
- 正規表現パターンの生成
Expects:
- 戻り値が期待値と一致する
"""
# Arranges
object_dict = {
"test_key": "test_value"
}
sut = DictChecker(object_dict)
pattern = r'[12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\.000Z'
# Act
actual = sut.check_match_pattern(pattern, "test_key")
# Expects
assert actual is False
assert actual is expect
def test_assert_key_exist(self) -> None:
"""