From a68027bb9f7c11e1be3970d8a6aa94002db7a157 Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Thu, 4 Aug 2022 15:33:31 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20json=5Fparser=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E5=87=A6=E7=90=86=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/parser/test_json_parse.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ecs/crm-datafetch/tests/parser/test_json_parse.py diff --git a/ecs/crm-datafetch/tests/parser/test_json_parse.py b/ecs/crm-datafetch/tests/parser/test_json_parse.py new file mode 100644 index 00000000..fe2c96ea --- /dev/null +++ b/ecs/crm-datafetch/tests/parser/test_json_parse.py @@ -0,0 +1,43 @@ +from src.parser.json_parse import JsonParser + + +class TestJsonParser(): + + def test_parse(self) -> dict: + """ + Cases: + - コメントアウトが記載されているJSONからコメントを取り除き、辞書型を返すこと + Arranges: + - JSON文字列を準備する + Expects: + - json.loadsされたファイルの内容が期待値と一致する + """ + + # Arranges + json_string = """{ + "aaaa": "aaaa", + # これはコメントです + "#これはコメントではありません": "#これはコメントではありません", + "bbb": false, + "hogehoge": [ + "ccc", + /これはコメントです + "/これはコメントではありません" + ] + }""" + + sut = JsonParser(json_string) + actual = sut.parse() + + # Expects + expected_value = { + "aaaa": "aaaa", + "#これはコメントではありません": "#これはコメントではありません", + "bbb": False, + "hogehoge": [ + "ccc", + "/これはコメントではありません" + ] + } + + assert actual == expected_value From bf5fedbfa3c1fb34b6cb77286035a9cbadec4bd9 Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Thu, 4 Aug 2022 18:17:47 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E7=95=B0=E5=B8=B8=E7=B3=BB?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/parser/test_json_parse.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ecs/crm-datafetch/tests/parser/test_json_parse.py b/ecs/crm-datafetch/tests/parser/test_json_parse.py index fe2c96ea..1991aa54 100644 --- a/ecs/crm-datafetch/tests/parser/test_json_parse.py +++ b/ecs/crm-datafetch/tests/parser/test_json_parse.py @@ -1,3 +1,4 @@ +import pytest from src.parser.json_parse import JsonParser @@ -26,6 +27,7 @@ class TestJsonParser(): ] }""" + # Act sut = JsonParser(json_string) actual = sut.parse() @@ -41,3 +43,35 @@ class TestJsonParser(): } assert actual == expected_value + + def test_raise_parse(self) -> dict: + """ + Cases: + - コメントアウト記号ではない文字をコメントアウトとしたときに、例外が発生すること + Arranges: + - JSON文字列を準備する + Expects: + - 例外が発生し期待値と一致する + """ + + # Arranges + json_string = """{ + "aaaa": "aaaa", + $ これはコメントです + "#これはコメントではありません": "#これはコメントではありません", + "bbb": false, + "hogehoge": [ + "ccc", + /これはコメントです + "/これはコメントではありません" + ] + }""" + + # Act + with pytest.raises(Exception) as e: + + sut = JsonParser(json_string) + sut.parse() + + # Expects + assert str(e.value) == "Expecting property name enclosed in double quotes: line 3 column 13 (char 42)" From d935bc2c3d687227d16af35af6029a6b5dbb5c14 Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Wed, 10 Aug 2022 09:25:00 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E6=8C=87=E6=91=98=E5=86=85=E5=AE=B9=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/crm-datafetch/tests/parser/test_json_parse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs/crm-datafetch/tests/parser/test_json_parse.py b/ecs/crm-datafetch/tests/parser/test_json_parse.py index 1991aa54..f670eb5e 100644 --- a/ecs/crm-datafetch/tests/parser/test_json_parse.py +++ b/ecs/crm-datafetch/tests/parser/test_json_parse.py @@ -74,4 +74,4 @@ class TestJsonParser(): sut.parse() # Expects - assert str(e.value) == "Expecting property name enclosed in double quotes: line 3 column 13 (char 42)" + assert "Expecting property name enclosed in double quotes:" in str(e.value) From ede652b8af7b68624e2cc8ac7bfdd7f706bac378 Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Tue, 16 Aug 2022 10:09:25 +0900 Subject: [PATCH 4/4] =?UTF-8?q?style:=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=90=8D=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/crm-datafetch/src/parser/{json_parse.py => json_parser.py} | 0 .../tests/parser/{test_json_parse.py => test_json_parser.py} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename ecs/crm-datafetch/src/parser/{json_parse.py => json_parser.py} (100%) rename ecs/crm-datafetch/tests/parser/{test_json_parse.py => test_json_parser.py} (98%) diff --git a/ecs/crm-datafetch/src/parser/json_parse.py b/ecs/crm-datafetch/src/parser/json_parser.py similarity index 100% rename from ecs/crm-datafetch/src/parser/json_parse.py rename to ecs/crm-datafetch/src/parser/json_parser.py diff --git a/ecs/crm-datafetch/tests/parser/test_json_parse.py b/ecs/crm-datafetch/tests/parser/test_json_parser.py similarity index 98% rename from ecs/crm-datafetch/tests/parser/test_json_parse.py rename to ecs/crm-datafetch/tests/parser/test_json_parser.py index f670eb5e..c343752b 100644 --- a/ecs/crm-datafetch/tests/parser/test_json_parse.py +++ b/ecs/crm-datafetch/tests/parser/test_json_parser.py @@ -1,5 +1,5 @@ import pytest -from src.parser.json_parse import JsonParser +from src.parser.json_parser import JsonParser class TestJsonParser():