Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Author now uses simplified testdict; tests updated - all pass #9

Merged
merged 1 commit into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/Author.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def author_signature_lines(self) -> List[str]:
[0, "https://github.com/plan-do-break-fix/TestyArthur"]
]

def author_setup_lines(self, instance_name: str, class_name: str
) -> List[str]:
def author_setup_lines(self, instance_name: str, class_name: str) -> List[str]:
return [[1, "def setUp(self):"],
[2, f"self.{instance_name} = {class_name}()"]
]
Expand All @@ -48,14 +47,13 @@ def author_test_definition(self, test: dict) -> str:
md5hash.update(test_str)
digest = md5hash.hexdigest()
fingerprint = hex(int(digest[:16], 16) ^ int(digest[16:], 16))[2:]
return f"def test_{test['method']}_{fingerprint}(self):"
return f"def test_{test['method'][0]}_{fingerprint}(self):"

def author_test_result(self, instance_name: str, method_name: str, args: List
) -> str:
line = f"result = self.{instance_name}.{method_name}("
line += f"\"{args[0]}\""
if len(args) > 1:
for arg in args[1:]:
def author_test_result(self, instance_name: str, method: List[str]) -> str:
line = f"result = self.{instance_name}.{method[0]}("
line += f"\"{method[1]}\""
if len(method) > 1:
for arg in method[2:]:
line += f", \"{arg}\""
line += ")"
return line
Expand All @@ -67,7 +65,7 @@ def author_test_assertion(self, assertion: List) -> str:
line += ")"
return line

def author_pydoc(self, testdoc: dict) -> bool:
def author_python_lines(self, testdoc: dict) -> bool:
target = testdoc["metadata"]["target"]
alias = testdoc["metadata"]["alias"]
lines = [[0, "#!/usr/bin/python3"],]
Expand All @@ -80,23 +78,23 @@ def author_pydoc(self, testdoc: dict) -> bool:
if "setup" in testdoc["metadata"].keys():
lines += self.author_setup_lines(alias, target[0])
lines.append(BLANK)
for method_tests in testdoc["tests"]:
method_name = list(method_tests.keys())[0]
for testdict in testdoc["tests"]:
method_name = testdict["method"][0]
for test in testdoc["tests"][method_name]:
lines += self.author_test(method_name,
testdoc["metadata"]["alias"],
test)
lines.append(BLANK)
if "teardown" in testdoc["metadata"].keys():
lines += self.author_teardown_lines(alias, target[0])
lines += self.author_teardown_lines(alias)
lines.append(BLANK)
lines = [self.indent(_l[0], _l[1]) for _l in lines]
return lines

def author_test(self, instance_name: str, test: dict) -> List[str]:
lines = []
lines.append([1, self.author_test_definition(test)])
lines.append([2, self.author_test_result(instance_name, test["method_name"], test["args"])])
lines.append([2, self.author_test_result(instance_name, test["method"])])
lines.append([2, self.author_test_assertion(test["assertion"])])
return lines

Expand Down
10 changes: 4 additions & 6 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ def test_author_teardown_lines(self):

def test_author_test_definition(self):
result = self.author.author_test_definition(self.testdoc["tests"][0])
expected = "def test_add_23da7c2f38800590(self):"
expected = "def test_add_f5eec4c1fe55b495(self):"
self.assertEqual(result, expected)

def test_author_test_result(self):
result = self.author.author_test_result(self.testdoc["metadata"]["alias"],
"add",
self.testdoc["tests"][0]["args"])
self.testdoc["tests"][0]["method"])
expected = "result = self.maths.add(\"2\", \"3\")"
self.assertEqual(result, expected)

Expand Down Expand Up @@ -119,13 +118,12 @@ def test_author_teardown_lines(self):

def test_author_test_definition(self):
result = self.author.author_test_definition(self.testdoc["tests"][0])
expected = "def test_drop_vowels_fb5c41aa2a79b0b4(self):"
expected = "def test_drop_vowels_c403c1ce99b5837a(self):"
self.assertEqual(result, expected)

def test_author_test_result(self):
result = self.author.author_test_result(self.testdoc["metadata"]["alias"],
"drop_vowels",
self.testdoc["tests"][0]["args"])
self.testdoc["tests"][0]["method"])
expected = "result = self.stringy.drop_vowels(\"you\")"
self.assertEqual(result, expected)

Expand Down
3 changes: 1 addition & 2 deletions test/testdocs/maths_test_doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
},
"tests": [
{
"method": "add",
"args": ["2", "3"],
"method": ["add", "2", "3"],
"assertion": ["Equal", "5"]
}
]
Expand Down
9 changes: 3 additions & 6 deletions test/testdocs/string_test_doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
},
"tests": [
{
"method": "drop_vowels",
"args": ["you"],
"method": ["drop_vowels", "you"],
"assertion": ["Equal", "y"]
},
{
"method": "drop_vowels",
"args": ["high life"],
"method": ["drop_vowels", "high life"],
"assertion": ["Equal", "hgh lf"]
},
{
"method": "drop_vowels",
"args": ["alphetbetical abstraction"],
"method": ["drop_vowels", "alphetbetical abstraction"],
"assertion": ["Equal", "lphbtcl bstrctn"]
}
]
Expand Down