From 37c8baeae90fdfb29c8c98738b6b6ce5d73a5711 Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Sun, 6 Nov 2016 20:20:00 +0900 Subject: [PATCH 1/7] Add python3 unit test. --- Python3Tester.py | 10 +++--- Python3TesterTest.py | 78 ++++++++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/Python3Tester.py b/Python3Tester.py index 75aadfc..daea88e 100644 --- a/Python3Tester.py +++ b/Python3Tester.py @@ -78,9 +78,7 @@ def test_regex(self, config, test_strings): "exception": str(e) } - print("##START_RESULT##") - print(json.dumps(result)) - print("##END_RESULT##") + return result def main(): @@ -88,7 +86,11 @@ def main(): test_strings = json.loads(sys.argv[2]) tester = Python3Tester() - tester.test_regex(config, test_strings) + result = tester.test_regex(config, test_strings) + + print("##START_RESULT##") + print(json.dumps(result)) + print("##END_RESULT##") if __name__ == "__main__": diff --git a/Python3TesterTest.py b/Python3TesterTest.py index d177f66..6869639 100644 --- a/Python3TesterTest.py +++ b/Python3TesterTest.py @@ -1,33 +1,53 @@ -import re +import unittest import json -import sys from Python3Tester import Python3Tester -tester = Python3Tester() -test_strings =["Hello Python Test!", "Hello2 Python2 Test2"] - -config = { - "test_type": "match", - "regex": "([A-Z])" -} -tester.test_regex(config, test_strings) - -config = { - "test_type": "group", - "regex": "([A-Za-z]*)" -} -tester.test_regex(config, test_strings) - -config = { - "test_type": "replace", - "regex": "([A-Z])", - "replaceString": "\\1_" -} -tester.test_regex(config, test_strings) - -config = { - "test_type": "findall", - "regex": "([A-Z])" -} -tester.test_regex(config, test_strings) \ No newline at end of file + +class Python3TesterTest(unittest.TestCase): + tester = Python3Tester() + test_strings = ["Hello Python Test!", "Hello2 Python2 Test2"] + + def test_match(self): + config = { + "test_type": "match", + "regex": "([A-Z])" + } + result = self.tester.test_regex(config, self.test_strings) + self.assertEqual(result["result"]["resultList"][0], True) + self.assertEqual(result["result"]["resultList"][1], True) + + def test_group(self): + config = { + "test_type": "group", + "regex": "([A-Za-z]*)" + } + result = self.tester.test_regex(config, self.test_strings) + self.assertEqual(result["result"]["resultList"][0]["list"][0], ["Hello"]) + self.assertEqual(result["result"]["resultList"][0]["list"][2], ["Python"]) + self.assertEqual(result["result"]["resultList"][0]["list"][4], ["Test"]) + self.assertEqual(result["result"]["resultList"][1]["list"][0], ["Hello"]) + self.assertEqual(result["result"]["resultList"][1]["list"][3], ["Python"]) + self.assertEqual(result["result"]["resultList"][1]["list"][6], ["Test"]) + + def test_replace(self): + config = { + "test_type": "replace", + "regex": "([A-Z])", + "replace": "\\1_" + } + result = self.tester.test_regex(config, self.test_strings) + self.assertEqual(result["result"]["resultList"][0], "H_ello P_ython T_est!") + self.assertEqual(result["result"]["resultList"][1], "H_ello2 P_ython2 T_est2") + + def test_findall(self): + config = { + "test_type": "findall", + "regex": "([A-Z])" + } + result = self.tester.test_regex(config, self.test_strings) + self.assertEqual(result["result"]["resultList"][0]["list"][0], ["H", "P", "T"]) + self.assertEqual(result["result"]["resultList"][1]["list"][0], ["H", "P", "T"]) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From ca3886aa6831734b12ec42047e776c75d325fb6a Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Mon, 7 Nov 2016 02:18:34 +0900 Subject: [PATCH 2/7] Add columns to group. --- Python3Tester.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Python3Tester.py b/Python3Tester.py index daea88e..10c3c55 100644 --- a/Python3Tester.py +++ b/Python3Tester.py @@ -46,6 +46,11 @@ def test_regex(self, config, test_strings): result["result"]["resultList"].append(False) elif test_type == "group": result["type"] = "GROUP" + result["columns"] = [] + + for i in range(1, len(pattern.groups())): + result["columns"].append("Group #" + i) + for test_string in test_strings: iterator = pattern.finditer(test_string) From 4259fafd96fa28380495b8c2a46f7323bd87d0e7 Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Mon, 7 Nov 2016 18:07:55 +0900 Subject: [PATCH 3/7] Fix group bug. --- Python3Tester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python3Tester.py b/Python3Tester.py index 10c3c55..f3198b6 100644 --- a/Python3Tester.py +++ b/Python3Tester.py @@ -48,8 +48,8 @@ def test_regex(self, config, test_strings): result["type"] = "GROUP" result["columns"] = [] - for i in range(1, len(pattern.groups())): - result["columns"].append("Group #" + i) + for i in range(1, pattern.groups + 1): + result["columns"].append("Group #" + str(i)) for test_string in test_strings: iterator = pattern.finditer(test_string) From 47f18a58fc4dae082b48e90041db7334ae02f6ed Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Mon, 7 Nov 2016 18:39:52 +0900 Subject: [PATCH 4/7] Fix result bug. --- Python3Tester.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Python3Tester.py b/Python3Tester.py index f3198b6..e8d3f6a 100644 --- a/Python3Tester.py +++ b/Python3Tester.py @@ -46,10 +46,10 @@ def test_regex(self, config, test_strings): result["result"]["resultList"].append(False) elif test_type == "group": result["type"] = "GROUP" - result["columns"] = [] + result["result"]["columns"] = [] for i in range(1, pattern.groups + 1): - result["columns"].append("Group #" + str(i)) + result["result"]["columns"].append("Group #" + str(i)) for test_string in test_strings: iterator = pattern.finditer(test_string) @@ -71,12 +71,13 @@ def test_regex(self, config, test_strings): result["result"]["resultList"].append(replaced) elif test_type == "findall": result["type"] = "GROUP" + result["result"]["columns"] = ["Found"]; for test_string in test_strings: groupsList = {"list": [[]]} result["result"]["resultList"].append(groupsList) found = pattern.findall(test_string) for word in found: - groupsList["list"][0].append(word); + groupsList["list"].append([word]); except Exception as e: result = { From 1b06f766cff5a628368333cad96dc99b7d7e0689 Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Mon, 7 Nov 2016 21:01:54 +0900 Subject: [PATCH 5/7] Add group 0. --- Python3Tester.py | 6 +++--- Python3TesterTest.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Python3Tester.py b/Python3Tester.py index e8d3f6a..ffe8e60 100644 --- a/Python3Tester.py +++ b/Python3Tester.py @@ -48,7 +48,7 @@ def test_regex(self, config, test_strings): result["type"] = "GROUP" result["result"]["columns"] = [] - for i in range(1, pattern.groups + 1): + for i in range(0, pattern.groups + 1): result["result"]["columns"].append("Group #" + str(i)) for test_string in test_strings: @@ -57,7 +57,7 @@ def test_regex(self, config, test_strings): groupsList = {"list": []} result["result"]["resultList"].append(groupsList) for match in iterator: - groups = [] + groups = [match.group(0)] for group in match.groups(): groups.append(group) groupsList["list"].append(groups); @@ -73,7 +73,7 @@ def test_regex(self, config, test_strings): result["type"] = "GROUP" result["result"]["columns"] = ["Found"]; for test_string in test_strings: - groupsList = {"list": [[]]} + groupsList = {"list": []} result["result"]["resultList"].append(groupsList) found = pattern.findall(test_string) for word in found: diff --git a/Python3TesterTest.py b/Python3TesterTest.py index 6869639..a01ebdc 100644 --- a/Python3TesterTest.py +++ b/Python3TesterTest.py @@ -1,5 +1,4 @@ import unittest -import json from Python3Tester import Python3Tester @@ -23,12 +22,12 @@ def test_group(self): "regex": "([A-Za-z]*)" } result = self.tester.test_regex(config, self.test_strings) - self.assertEqual(result["result"]["resultList"][0]["list"][0], ["Hello"]) - self.assertEqual(result["result"]["resultList"][0]["list"][2], ["Python"]) - self.assertEqual(result["result"]["resultList"][0]["list"][4], ["Test"]) - self.assertEqual(result["result"]["resultList"][1]["list"][0], ["Hello"]) - self.assertEqual(result["result"]["resultList"][1]["list"][3], ["Python"]) - self.assertEqual(result["result"]["resultList"][1]["list"][6], ["Test"]) + self.assertEqual(result["result"]["resultList"][0]["list"][0], ["Hello", "Hello"]) + self.assertEqual(result["result"]["resultList"][0]["list"][2], ["Python", "Python"]) + self.assertEqual(result["result"]["resultList"][0]["list"][4], ["Test", "Test"]) + self.assertEqual(result["result"]["resultList"][1]["list"][0], ["Hello", "Hello"]) + self.assertEqual(result["result"]["resultList"][1]["list"][3], ["Python", "Python"]) + self.assertEqual(result["result"]["resultList"][1]["list"][6], ["Test", "Test"]) def test_replace(self): config = { @@ -46,8 +45,8 @@ def test_findall(self): "regex": "([A-Z])" } result = self.tester.test_regex(config, self.test_strings) - self.assertEqual(result["result"]["resultList"][0]["list"][0], ["H", "P", "T"]) - self.assertEqual(result["result"]["resultList"][1]["list"][0], ["H", "P", "T"]) + self.assertEqual(result["result"]["resultList"][0]["list"], [["H"], ["P"], ["T"]]) + self.assertEqual(result["result"]["resultList"][1]["list"], [["H"], ["P"], ["T"]]) if __name__ == '__main__': unittest.main() \ No newline at end of file From 322f241bce57f294736b7688b46582f5998b242a Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Mon, 14 Nov 2016 02:17:23 +0900 Subject: [PATCH 6/7] Apply parameter base64 encoding. --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0dadb15..c2fe358 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.4 +FROM regexpress/base:latest COPY Python3Tester.py /root/Python3Tester.py COPY Python3TesterTest.py /root/Python3TesterTest.py @@ -9,7 +9,7 @@ RUN apk add --no-cache python3 && \ pip3 install --upgrade pip setuptools && \ rm -r /root/.cache && \ cd /root && \ - echo "python3 /root/Python3Tester.py \"\$@\"" > run.sh && \ + echo "arg=();for var in \"\$@\";do arg+=(\$(echo -n \"\$var\" | base64 -d)); done; python3 /root/Python3Tester.py \"\${arg[@]}\"" > run.sh && \ chmod 755 run.sh -ENTRYPOINT ["/bin/sh", "/root/run.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "/root/run.sh"] \ No newline at end of file From ffb31b3039a02c6afb5e04b00ac0c225c8a59e53 Mon Sep 17 00:00:00 2001 From: bdh92123 Date: Sun, 20 Nov 2016 19:07:14 +0900 Subject: [PATCH 7/7] Fix parameter bug. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c2fe358..f4c67fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN apk add --no-cache python3 && \ pip3 install --upgrade pip setuptools && \ rm -r /root/.cache && \ cd /root && \ - echo "arg=();for var in \"\$@\";do arg+=(\$(echo -n \"\$var\" | base64 -d)); done; python3 /root/Python3Tester.py \"\${arg[@]}\"" > run.sh && \ + echo "arg=();for var in \"\$@\";do arg+=(\"\$(echo -n \"\$var\" | base64 -d)\"); done; python3 /root/Python3Tester.py \"\${arg[@]}\"" > run.sh && \ chmod 755 run.sh ENTRYPOINT ["/bin/bash", "/root/run.sh"] \ No newline at end of file