-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ def main(): | |
| for commit in commits: | ||
| checkout_commit(commit.hash) | ||
| all_wordcounts[commit] = get_wordcounts() | ||
| filenames.update(set(wc.filename for wc in all_wordcounts[commit])) | ||
| filenames.update({wc.filename for wc in all_wordcounts[commit]}) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function main refactored with the following changes:
|
||
|
|
||
| with open(os.path.join(BOOK_ROOT, 'wordcounts.tsv'), 'w') as csvfile: | ||
| fieldnames = ['date.{}'.format(thing) for thing in ['year', 'month', 'day', 'hour']] | ||
|
|
@@ -58,14 +58,16 @@ def main(): | |
| writer = csv.DictWriter(csvfile, fieldnames, dialect="excel-tab") | ||
| writer.writeheader() | ||
| for commit, wordcounts in all_wordcounts.items(): | ||
| row = {} | ||
| row['hash'] = commit.hash | ||
| row['subject'] = commit.subject | ||
| row['date'] = '' | ||
| row['date.year'] = commit.date.year | ||
| row['date.month'] = commit.date.month | ||
| row['date.day'] = commit.date.day | ||
| row['date.hour'] = commit.date.hour | ||
| row = { | ||
| 'hash': commit.hash, | ||
| 'subject': commit.subject, | ||
| 'date': '', | ||
| 'date.year': commit.date.year, | ||
| 'date.month': commit.date.month, | ||
| 'date.day': commit.date.day, | ||
| 'date.hour': commit.date.hour, | ||
| } | ||
|
|
||
| for wordcount in wordcounts: | ||
| row[wordcount.filename + " (words)"] = wordcount.words | ||
| row[wordcount.filename + " (lines)"] = wordcount.lines | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,7 @@ def get_data_from_csv(): | |
| for field in reader.fieldnames: | ||
| if 'words' in field: | ||
| val = row[field] | ||
| if val: | ||
| fixed_row[field] = val | ||
| else: | ||
| fixed_row[field] = 0 | ||
| fixed_row[field] = val if val else 0 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function get_data_from_csv refactored with the following changes:
|
||
| date = datetime(int(row['date.year']), int(row['date.month']), int(row['date.day']), int(row['date.hour']),) | ||
| fixed_row['date'] = date | ||
| data.append(fixed_row) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,11 +121,7 @@ def parse_output(listing): | |
|
|
||
| outputs = [] | ||
| output_before = listing.text | ||
| if output_before: | ||
| output_before = fix_newlines(output_before.strip()) | ||
| else: | ||
| output_before = '' | ||
|
|
||
| output_before = fix_newlines(output_before.strip()) if output_before else '' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function parse_output refactored with the following changes:
|
||
| for command in commands: | ||
| if '$' in output_before and '\n' in output_before: | ||
| last_cr = output_before.rfind('\n') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,8 +42,8 @@ | |
|
|
||
| def contains(inseq, subseq): | ||
| return any( | ||
| inseq[pos:pos + len(subseq)] == subseq | ||
| for pos in range(0, len(inseq) - len(subseq) + 1) | ||
| inseq[pos : pos + len(subseq)] == subseq | ||
| for pos in range(len(inseq) - len(subseq) + 1) | ||
|
Comment on lines
-45
to
+46
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function contains refactored with the following changes:
|
||
| ) | ||
|
|
||
|
|
||
|
|
@@ -73,12 +73,11 @@ def strip_mock_ids(output): | |
| r"Mock name='\1' id='XX'>", | ||
| output, | ||
| ) | ||
| strip_all_mocks = re.sub( | ||
| return re.sub( | ||
| r"Mock id='(\d+)'>", | ||
| r"Mock id='XX'>", | ||
| strip_mocks_with_names, | ||
| ) | ||
| return strip_all_mocks | ||
|
Comment on lines
-76
to
-81
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function strip_mock_ids refactored with the following changes:
|
||
|
|
||
| def strip_object_ids(output): | ||
| return re.sub('0x([0-9a-f]+)>', '0xXX>', output) | ||
|
|
@@ -106,13 +105,12 @@ def strip_git_hashes(output): | |
| r"index XXXXXXX\.\.XXXXXXX 100644", | ||
| output, | ||
| ) | ||
| fixed_commit_numbers = re.sub( | ||
| return re.sub( | ||
| r"^[a-f0-9]{7} ", | ||
| r"XXXXXXX ", | ||
| fixed_indexes, | ||
| flags=re.MULTILINE, | ||
| ) | ||
| return fixed_commit_numbers | ||
|
Comment on lines
-109
to
-115
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function strip_git_hashes refactored with the following changes:
|
||
|
|
||
|
|
||
| def strip_callouts(output): | ||
|
|
@@ -122,13 +120,12 @@ def strip_callouts(output): | |
| output, | ||
| flags=re.MULTILINE, | ||
| ) | ||
| minus_new_callouts = re.sub( | ||
| return re.sub( | ||
| r"^(.+) \(\d+\)$", | ||
| r"\1", | ||
| minus_old_callouts, | ||
| flags=re.MULTILINE, | ||
| ) | ||
| return minus_new_callouts | ||
|
Comment on lines
-125
to
-131
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function strip_callouts refactored with the following changes:
|
||
|
|
||
|
|
||
| def standardise_library_paths(output): | ||
|
|
@@ -527,9 +524,12 @@ def assert_console_output_correct(self, actual, expected, ls=False): | |
| else: | ||
| self.assertLineIn(line, [l.strip() for l in actual_lines]) | ||
|
|
||
| if len(expected_lines) > 4 and '[...' not in expected_fixed: | ||
| if expected.type != 'qunit output': | ||
| self.assertMultiLineEqual(actual_fixed.strip(), expected_fixed.strip()) | ||
| if ( | ||
| len(expected_lines) > 4 | ||
| and '[...' not in expected_fixed | ||
| and expected.type != 'qunit output' | ||
| ): | ||
| self.assertMultiLineEqual(actual_fixed.strip(), expected_fixed.strip()) | ||
|
Comment on lines
-530
to
+532
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function ChapterTest.assert_console_output_correct refactored with the following changes:
|
||
|
|
||
| expected.was_checked = True | ||
|
|
||
|
|
@@ -614,10 +614,6 @@ def unset_PYTHONDONTWRITEBYTECODE(self): | |
|
|
||
| def _strip_out_any_pycs(self): | ||
| return | ||
| self.sourcetree.run_command( | ||
| r"find . -name __pycache__ -exec rm -rf {} \;", | ||
| ignore_errors=True | ||
| ) | ||
|
Comment on lines
-617
to
-620
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function ChapterTest._strip_out_any_pycs refactored with the following changes:
|
||
|
|
||
|
|
||
| def run_test_and_check_result(self, bdd=False): | ||
|
|
@@ -654,12 +650,6 @@ def run_js_tests(self, tests_path): | |
| print('fixed phantomjs output', output) | ||
| return output | ||
|
|
||
| os.chmod(SLIMERJS_BINARY, os.stat(SLIMERJS_BINARY).st_mode | stat.S_IXUSR) | ||
| os.environ['SLIMERJSLAUNCHER'] = '/usr/bin/firefox' | ||
| return subprocess.check_output( | ||
| ['xvfb-run', '--auto-servernum', SLIMERJS_BINARY, PHANTOMJS_RUNNER, tests_path] | ||
| ).decode() | ||
|
Comment on lines
652
to
-661
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function ChapterTest.run_js_tests refactored with the following changes:
|
||
|
|
||
|
|
||
| def check_qunit_output(self, expected_output): | ||
| lists_tests = os.path.join( | ||
|
|
@@ -735,9 +725,10 @@ def check_diff_or_status(self, pos): | |
| 'diff' in self.listings[pos] or 'status' in self.listings[pos] | ||
| ) | ||
| git_output = self.run_command(self.listings[pos]) | ||
| if not any('/' + l in git_output for l in LIKELY_FILES): | ||
| if not any(f in git_output for f in ('lists/', 'functional_tests.py')): | ||
| self.fail('no likely files in diff output %s' % (git_output,)) | ||
| if all('/' + l not in git_output for l in LIKELY_FILES) and all( | ||
| f not in git_output for f in ('lists/', 'functional_tests.py') | ||
| ): | ||
| self.fail('no likely files in diff output %s' % (git_output,)) | ||
|
Comment on lines
-738
to
+731
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function ChapterTest.check_diff_or_status refactored with the following changes:
|
||
| self.pos += 1 | ||
| comment = self.listings[pos + 1] | ||
| if comment.skip: | ||
|
|
@@ -823,11 +814,7 @@ def run_interactive_manage_py(self, listing): | |
| expected_output = output_before | ||
| output_after = None | ||
| next_output = None | ||
| if user_input == '2': | ||
| ignore_errors = True | ||
| else: | ||
| ignore_errors = False | ||
|
|
||
| ignore_errors = True if user_input == '2' else False | ||
|
Comment on lines
-826
to
+817
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function ChapterTest.run_interactive_manage_py refactored with the following changes:
|
||
| else: | ||
| user_input = None | ||
| expected_output = output_before | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ def which(program): | |
| if SLIMERJSLAUNCHER == "": | ||
| POSSIBLE_PATH = [] | ||
|
|
||
| if sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin": | ||
| if sys.platform in ["linux", "linux2", "darwin"]: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 42-42 refactored with the following changes:
|
||
| POSSIBLE_PATH.append(os.path.join(SLIMERJS_PATH, "xulrunner", "xulrunner")) | ||
| path = which('firefox') | ||
| if path != None: | ||
|
|
@@ -139,7 +139,7 @@ def showHelp(): | |
| "--reset-profile","--profile","--p","--createprofile","--profilemanager", | ||
| ] | ||
| for arg in SYS_ARGS: | ||
| if arg == '--help' or arg == "-h": | ||
| if arg in ['--help', "-h"]: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 142-193 refactored with the following changes:
|
||
| showHelp() | ||
| sys.exit(0) | ||
|
|
||
|
|
@@ -165,8 +165,11 @@ def showHelp(): | |
| os.environ.data['__SLIMER_ARGS'] = string.join(SYS_ARGS,' ') | ||
|
|
||
| # launch slimerjs with firefox/xulrunner | ||
| SLCMD = [ SLIMERJSLAUNCHER ] | ||
| SLCMD.extend(["-app", os.path.join(SLIMERJS_PATH, "application.ini"), "-no-remote"]) | ||
| SLCMD = [ | ||
| SLIMERJSLAUNCHER, | ||
| *["-app", os.path.join(SLIMERJS_PATH, "application.ini"), "-no-remote"], | ||
| ] | ||
|
|
||
| if sys.platform == "win32": | ||
| SLCMD.extend(["-attach-console"]) | ||
| SLCMD.extend(PROFILE) | ||
|
|
@@ -190,5 +193,5 @@ def showHelp(): | |
|
|
||
| if CREATE_TEMP: | ||
| shutil.rmtree(PROFILE_DIR) | ||
|
|
||
| sys.exit(exitCode) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,11 +174,10 @@ def find_first_nonimport_line(self): | |
| except StopIteration: | ||
| return len(self.lines) | ||
| pos = self.lines.index(first_nonimport) | ||
| if self._import_nodes: | ||
| if pos < max(n.lineno for n in self._import_nodes): | ||
| raise SourceUpdateError('first nonimport (%s) was before end of imports (%s)' % ( | ||
| first_nonimport, max(n.lineno for n in self._import_nodes)) | ||
| ) | ||
| if self._import_nodes and pos < max(n.lineno for n in self._import_nodes): | ||
| raise SourceUpdateError('first nonimport (%s) was before end of imports (%s)' % ( | ||
| first_nonimport, max(n.lineno for n in self._import_nodes)) | ||
| ) | ||
|
Comment on lines
-177
to
+180
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Source.find_first_nonimport_line refactored with the following changes:
|
||
| return pos | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,17 +30,17 @@ def from_diff(commit_info): | |
| commit.all_lines = commit.info.split('\n') | ||
|
|
||
| commit.lines_to_add = [ | ||
| l[1:] for l in commit.all_lines | ||
| if l.startswith('+') and | ||
| l[1:].strip() and | ||
| not l[1] == '+' | ||
| l[1:] | ||
| for l in commit.all_lines | ||
| if l.startswith('+') and l[1:].strip() and l[1] != '+' | ||
| ] | ||
|
|
||
| commit.lines_to_remove = [ | ||
| l[1:] for l in commit.all_lines | ||
| if l.startswith('-') and | ||
| l[1:].strip() and | ||
| not l[1] == '-' | ||
| l[1:] | ||
| for l in commit.all_lines | ||
| if l.startswith('-') and l[1:].strip() and l[1] != '-' | ||
| ] | ||
|
|
||
|
Comment on lines
-33
to
+43
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Commit.from_diff refactored with the following changes:
|
||
| commit.moved_lines = [ | ||
| l for l in commit.lines_to_add if l in commit.lines_to_remove | ||
| ] | ||
|
|
@@ -130,7 +130,6 @@ def run_command(self, command, cwd=None, user_input=None, ignore_errors=False, s | |
| print(output) | ||
| except io.BlockingIOError as e: | ||
| print(e) | ||
| pass | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function SourceTree.run_command refactored with the following changes:
|
||
| return output | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -641,8 +641,8 @@ def test_ignores_3_5_x_AssertionError_None_thing(self): | |
| actual = "AssertionError" | ||
| expected = Output("AssertionError: None") | ||
| self.assert_console_output_correct(actual, expected) | ||
| actual2 = "AssertionError: something" | ||
| with self.assertRaises(AssertionError): | ||
| actual2 = "AssertionError: something" | ||
|
Comment on lines
-644
to
+645
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function AssertConsoleOutputCorrectTest.test_ignores_3_5_x_AssertionError_None_thing refactored with the following changes:
|
||
| self.assert_console_output_correct(actual2, expected) | ||
|
|
||
|
|
||
|
|
@@ -662,9 +662,9 @@ def test_ignores_localhost_server_port_5_digits(self): | |
|
|
||
|
|
||
| def test_only_ignores_exactly_32_char_strings_no_whitespace(self): | ||
| actual = "qnslckvp2aga7tm6xuivyb0ob1akzzwl" | ||
| expected = Output("jvhzc8kj2mkh06xooqq9iciptead20qq") | ||
| with self.assertRaises(AssertionError): | ||
| actual = "qnslckvp2aga7tm6xuivyb0ob1akzzwl" | ||
|
Comment on lines
-665
to
+667
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function AssertConsoleOutputCorrectTest.test_only_ignores_exactly_32_char_strings_no_whitespace refactored with the following changes:
|
||
| self.assert_console_output_correct(actual[:-1], expected[:-1]) | ||
| self.assert_console_output_correct(actual + '1', expected + 'a') | ||
| self.assert_console_output_correct(' ' + actual, ' ' + expected) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ def test_listings_and_commands_and_output(self): | |
|
|
||
| self.start_with_checkout() | ||
|
|
||
| vm_restore = 'MAKING_END' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Chapter9cTest.test_listings_and_commands_and_output refactored with the following changes:
|
||
| # hack fast-forward | ||
| skip = False | ||
| if skip: | ||
|
|
@@ -31,6 +30,7 @@ def test_listings_and_commands_and_output(self): | |
| )) | ||
|
|
||
| if DO_SERVER_COMMANDS: | ||
| vm_restore = 'MAKING_END' | ||
| subprocess.check_call(['vagrant', 'snapshot', 'restore', vm_restore]) | ||
|
|
||
| self.current_server_cd = '~/sites/superlists-staging.ottg.eu' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,6 @@ def test_listings_and_commands_and_output(self): | |
| ' && git reset --hard origin/chapter_making_deployment_production_ready', | ||
| ) | ||
|
|
||
| vm_restore = 'MANUAL_END' | ||
|
|
||
|
Comment on lines
-43
to
-44
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Chapter9bTest.test_listings_and_commands_and_output refactored with the following changes:
|
||
| # hack fast-forward | ||
| skip = False | ||
| if skip: | ||
|
|
@@ -51,6 +49,8 @@ def test_listings_and_commands_and_output(self): | |
| )) | ||
|
|
||
| if DO_SERVER_COMMANDS: | ||
| vm_restore = 'MANUAL_END' | ||
|
|
||
| subprocess.check_call(['vagrant', 'snapshot', 'restore', vm_restore]) | ||
|
|
||
| self.current_server_cd = '~/sites/$SITENAME' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,6 @@ def test_listings_and_commands_and_output(self): | |
| self.start_with_checkout() | ||
| self.prep_database() | ||
|
|
||
| vm_restore = 'FABRIC_END' | ||
|
|
||
|
Comment on lines
-38
to
-39
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Chapter18Test.test_listings_and_commands_and_output refactored with the following changes:
|
||
| # hack fast-forward | ||
| skip = False | ||
| if skip: | ||
|
|
@@ -46,6 +44,8 @@ def test_listings_and_commands_and_output(self): | |
| )) | ||
|
|
||
| if DO_SERVER_COMMANDS: | ||
| vm_restore = 'FABRIC_END' | ||
|
|
||
| subprocess.check_call(['vagrant', 'snapshot', 'restore', vm_restore]) | ||
|
|
||
| while self.pos < len(self.listings): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,7 +644,7 @@ def test_finding_start_line(self): | |
| assert source.find_start_line(['bla bla', 'whatever']) == 3 | ||
| assert source.find_start_line(['indented', 'whatever']) == 4 | ||
| assert source.find_start_line([' indented', 'whatever']) == 4 | ||
| assert source.find_start_line(['no such line', 'whatever']) == None | ||
| assert source.find_start_line(['no such line', 'whatever']) is None | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function LineFindingTests.test_finding_start_line refactored with the following changes:
|
||
| with self.assertRaises(SourceUpdateError): | ||
| source.find_start_line(['']) | ||
| with self.assertRaises(SourceUpdateError): | ||
|
|
@@ -666,8 +666,8 @@ def test_finding_end_line(self): | |
|
|
||
| assert source.find_end_line(['stuff', 'things']) == 1 | ||
| assert source.find_end_line(['bla bla', 'whatever', 'more']) == 5 | ||
| assert source.find_end_line(['bla bla', 'whatever']) == None | ||
| assert source.find_end_line(['no such line', 'whatever']) == None | ||
| assert source.find_end_line(['bla bla', 'whatever']) is None | ||
| assert source.find_end_line(['no such line', 'whatever']) is None | ||
|
Comment on lines
-669
to
+670
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function LineFindingTests.test_finding_end_line refactored with the following changes:
|
||
| with self.assertRaises(SourceUpdateError): | ||
| source.find_end_line([]) | ||
| with self.assertRaises(SourceUpdateError): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function add refactored with the following changes: