Skip to content

Commit

Permalink
resolve syntaxwarning on invalid escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead committed Jan 17, 2024
1 parent c4aa4bd commit f5b8cc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/protocols/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run(self, messages):
def replaced(self, contents):
"""For a question snippet containing some default code, return True if the
default code is replaced. Default code in a snippet should have
'\# Replace with your solution' at the end of each line.
'# Replace with your solution' at the end of each line.
"""
line_num = len(contents.strip(' ').splitlines())
replace_marks = self.RE_REPLACE_MARK.findall(contents.strip())
Expand Down
24 changes: 12 additions & 12 deletions client/protocols/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def new_f(*args, **kwargs):
return decorate

class TestingProtocol(models.Protocol):
"""A Protocol that executes doctests as lists of Example objects, supports
suite/case specificity, alternate file testing, and provides users with
"""A Protocol that executes doctests as lists of Example objects, supports
suite/case specificity, alternate file testing, and provides users with
details such as cases passed and test coverage.
"""
def __init__(self, args, assignment):
Expand All @@ -78,14 +78,14 @@ def test(self, good_env={}, suite=None, case=None):
exs = self.get_suite_examples(suite, case)
elif case:
# No support for cases without their suite
raise EarlyExit('python3 ok: error: '
raise EarlyExit('python3 ok: error: '
'Please specify suite for given case ({}).'.format(case[0]))
else:
exs = self.get_all_examples()
# gets analytics to be returned
test_results[self.tstfile_name] = self.analyze(suite, case, exs)
except KeyError as e:
raise EarlyExit('python3 ok: error: '
raise EarlyExit('python3 ok: error: '
'Suite/Case label must be valid.'
'(Suites: {}, Cases: {})'.format(self.num_suites, self.num_cases))
return test_results
Expand All @@ -94,7 +94,7 @@ def analyze(self, suite, case, examples):
failed, attempted = self.run_examples(examples)
self.cov.stop()
passed = attempted - failed
format.print_test_progress_bar( '{} summary'.format(self.tstfile_name),
format.print_test_progress_bar( '{} summary'.format(self.tstfile_name),
passed, failed, verbose=self.verb)
# only support test coverage stats when running everything
if not suite:
Expand All @@ -104,7 +104,7 @@ def analyze(self, suite, case, examples):
print("Maximum coverage achieved! Great work!")
else:
self.give_suggestions()
return {'suites_total' : self.num_suites, 'cases_total': self.num_cases,
return {'suites_total' : self.num_suites, 'cases_total': self.num_cases,
'exs_failed' : failed, 'exs_passed' : passed, 'attempted' : attempted,
'actual_cov' : self.lines_exec, 'total_cov' : self.lines_total}

Expand All @@ -116,7 +116,7 @@ def give_suggestions(self):
missing_cov = cov_stats[3]
if missing_cov:
print(' File: {}'.format(file))
missing_string = ' Line(s): ' + ','.join(map(str, missing_cov))
missing_string = ' Line(s): ' + ','.join(map(str, missing_cov))
print(missing_string)


Expand Down Expand Up @@ -199,13 +199,13 @@ def get_data(self):
self.data = collections.OrderedDict()
self.shared_case_data = collections.OrderedDict()
# chunk the file into suites
data_suites = re.findall("(Suite\s*([\d\w]+))((?:(?!Suite)(.|\n))*)", data_str)
data_suites = re.findall(r"(Suite\s*([\d\w]+))((?:(?!Suite)(.|\n))*)", data_str)
self.num_suites = len(data_suites)
self.num_cases = 0
for curr_suite in data_suites:
case_data = collections.OrderedDict()
# chunk the suite into cases
cases = re.findall("(Case\s*([\d\w]+))((?:(?!Case)(.|\n))*)", curr_suite[2])
cases = re.findall(r"(Case\s*([\d\w]+))((?:(?!Case)(.|\n))*)", curr_suite[2])
self.num_cases += len(cases)
self.shared_case_data[str(curr_suite[1])] = re.match("((?:(?!Case)(.|\n))*)", curr_suite[2])
for curr_case in cases:
Expand Down Expand Up @@ -234,13 +234,13 @@ def print_coverage(self):
lines, executed = self.get_coverage(self.cov)
self.lines_total = lines
self.lines_exec = executed
format.print_coverage_bar( 'Coverage summary',
format.print_coverage_bar( 'Coverage summary',
self.lines_exec, self.lines_total,verbose=self.verb)

def get_coverage(self, cov):
# returns executable lines, executed_lines
lines_run = 0
total_lines = 0
total_lines = 0
for file in self.clean_src:
file_cov = cov.analysis2(file + '.py')
lines = len(file_cov[1])
Expand All @@ -254,7 +254,7 @@ def run(self, messages, testloc=CURR_DIR):
if self.args.score or self.args.unlock or not self.args.testing:
return

# Note: All (and only) .py files given in the src will be tracked and
# Note: All (and only) .py files given in the src will be tracked and
# contribute to coverage statistics
self.clean_src = [i[:-3] for i in self.assignment.src if i.endswith('.py')]
self.cov = coverage(source=[testloc], include=[file + '.py' for file in self.clean_src])
Expand Down
2 changes: 1 addition & 1 deletion client/sources/doctest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Doctest(models.Test):

IMPORT_STRING = 'from {} import *'
SETUP = PS1 + IMPORT_STRING
prompt_re = re.compile(r'(\s*)({}|{})'.format(PS1, '\.\.\. '))
prompt_re = re.compile(r'(\s*)({}|{})'.format(PS1, r'\.\.\. '))

def __init__(self, file, verbose, interactive, timeout=None, ignore_empty=False, parsons=False, **fields):
super().__init__(**fields)
Expand Down

0 comments on commit f5b8cc1

Please sign in to comment.