Move tests into own file

This commit is contained in:
Louis Elkner-Alfaro 2023-10-04 09:13:00 -07:00
parent ff9237db25
commit 7708c61892
2 changed files with 72 additions and 50 deletions

View file

@ -19,35 +19,19 @@ projects = {
"Housing Works": ("housingworks", "app-housingworks-net"),
}
def test_parse_notes_section():
if (parse_notes_section('Resolved Issue #4, #5 and Issue 6') == ['4', '5', '6']):
print("TEST PARSE NOTES SECTION PASSED")
else:
print("TEST PARSE NOTES SECTION FAILED")
def test_get_issue_title_and_url():
solution = [
"Little slow downs are happening - these often signal that the server memory is getting overwhelmed?",
"https://git.agaric.com/housingworks/app-housingworks-net/issues/363"
issue_fields = [
"First Issue Title",
"First Issue URL",
"Second Issue Title",
"Second Issue URL",
"Third Issue Title",
"Third Issue URL"
]
if get_issue_title_and_url(363) == solution:
print("TEST GET ISSUE TITLE AND URL PASSED")
else:
print("TEST GET ISSUE TITLE AND URL FAILED")
def parse_notes_section(notes):
regex_pattern = r"[Ii]ssue\s*(?:#)?\d+|#\d+"
matches = re.findall(regex_pattern, notes)[:3]
issue_numbers = []
for match in matches:
match = re.search(r"\d+", match).group()
issue_numbers.append(match)
return issue_numbers
issues_and_urls = []
def get_issue_title_and_url(issue_number):
global issues_and_urls
issues_and_urls = []
owner = projects["Housing Works"][0]
repo = projects["Housing Works"][1]
issue_url = forgejo_issue_api_string.format(owner=owner, repo=repo, index=issue_number)
@ -67,6 +51,22 @@ def prompt_for_file(file):
print(file)
return file
def split_issues_into_columns(issues):
for issue in issues:
get_issue_title_and_url(issue)
issues_dict = dict(zip(issue_fields, issues_and_urls))
return issues_dict
def parse_notes_section(notes):
regex_pattern = r"[Ii]ssue\s*(?:#)?\d+|#\d+"
matches = re.findall(regex_pattern, notes)[:3]
issue_numbers = []
for match in matches:
match = re.search(r"\d+", match).group()
issue_numbers.append(match)
return issue_numbers
def parse_harvest_csv(file=None):
global issues_and_urls
@ -75,42 +75,28 @@ def parse_harvest_csv(file=None):
print('Beginning parsing for issues')
issue_fields = [
"First Issue Title",
"First Issue URL",
"Second Issue Title",
"Second Issue URL",
"Third Issue Title",
"Third Issue URL"
]
with open(file, 'r') as f:
csv_reader = csv.DictReader(f)
rows = list(csv_reader)
original_fieldnames = csv_reader.fieldnames
modified_fieldnames = original_fieldnames + issue_fields
f.close()
with open('modified_report.csv', 'w', newline='') as csvfile:
issues_and_urls = []
writer = csv.DictWriter(csvfile, fieldnames = modified_fieldnames)
writer.writeheader()
row_count = 0
for row in rows:
if (row_count % 20 == 0):
print("ON ROW:", row_count)
issues = parse_notes_section(row['Notes'])
for issue in issues:
get_issue_title_and_url(issue)
issues_dict = dict(zip(issue_fields, issues_and_urls))
issues_dict = split_issues_into_columns(issues)
row.update(issues_dict)
issues_and_urls = []
writer.writerow(row)
issues_and_urls = []
row_count += 1
def run_program():
if __name__ == "__main__":
parse_harvest_csv()
test_parse_notes_section()
test_get_issue_title_and_url()
run_program()

36
tests.py Normal file
View file

@ -0,0 +1,36 @@
import generate_issues
import re
def test_split_issues_into_columns():
issues_string = 'Resolved Issue #363, #362 and Issue 361'
issues = generate_issues.parse_notes_section(issues_string)
solution = {'First Issue Title': 'Little slow downs are happening - these often signal that the server memory is getting overwhelmed?', 'First Issue URL': 'https://git.agaric.com/housingworks/app-housingworks-net/issues/363', 'Second Issue Title': 'Little slow downs are happening - these often signal that the server memory is getting overwhelmed?', 'Second Issue URL': 'https://git.agaric.com/housingworks/app-housingworks-net/issues/363', 'Third Issue Title': 'the csv Importer has quit working on both the live and test sites???', 'Third Issue URL': 'https://git.agaric.com/housingworks/app-housingworks-net/issues/362'}
if (generate_issues.split_issues_into_columns(issues) == solution):
print("TEST SPLIT ISSUES INTO COLUMNS PASSED")
else:
print("TEST SPLIT ISSUES INTO COLUMNS FAILED")
def test_parse_notes_section():
if (generate_issues.parse_notes_section('Resolved Issue #4, #5 and Issue 6') == ['4', '5', '6']):
print("TEST PARSE NOTES SECTION PASSED")
else:
print("TEST PARSE NOTES SECTION FAILED")
def test_get_issue_title_and_url():
solution = [
"Little slow downs are happening - these often signal that the server memory is getting overwhelmed?",
"https://git.agaric.com/housingworks/app-housingworks-net/issues/363"
]
if generate_issues.get_issue_title_and_url(363) == solution:
print("TEST GET ISSUE TITLE AND URL PASSED")
else:
print("TEST GET ISSUE TITLE AND URL FAILED")
def run_tests():
test_parse_notes_section()
test_get_issue_title_and_url()
test_split_issues_into_columns()
run_tests()