Skip to content

Commit

Permalink
Rename "onelined", "to_one_line" to use "onelinerize" as verb
Browse files Browse the repository at this point in the history
  • Loading branch information
csvoss committed May 19, 2018
1 parent 51ad1e5 commit 7f6a35e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def generic_visit(self, tree):


# The entry point for everything.
def to_one_line(original):
def onelinerize(original):
# original :: string
# :: string
t = ast.parse(original)
Expand Down Expand Up @@ -808,12 +808,12 @@ def to_one_line(original):
infile = open(args.infile)
original = infile.read().strip()
infile.close()
onelined = to_one_line(original)
onelinerized = onelinerize(original)
if outfilename is None:
print onelined
print onelinerized
else:
outfi = open(outfilename, 'w')
outfi.write(onelined + '\n')
outfi.write(onelinerized + '\n')
outfi.close()

if args.debug:
Expand All @@ -828,11 +828,11 @@ def to_one_line(original):
exec(original, scope)
except Exception as e:
traceback.print_exc(e)
print '--- ONELINED ---------------------------------'
print onelined
print '--- ONELINERIZED -----------------------------'
print onelinerized
print '----------------------------------------------'
scope = {}
try:
exec(onelined, scope)
exec(onelinerized, scope)
except Exception as e:
traceback.print_exc(e)
15 changes: 7 additions & 8 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
import sys
from StringIO import StringIO
from main import to_one_line
from main import onelinerize

TEST_DIRECTORY = 'tests'

Expand All @@ -14,17 +14,17 @@ def runTest(self):
pass

def make_test(filename):
"""Return a function that verifies that the file and its onelined version
both output the same."""
"""Return a function that verifies that the file and its onelinerized
version both output the same."""

def new_test(self):
with open(filename, 'r') as fi:
self.longMessage = True
original = fi.read().strip()
onelined = to_one_line(original)
onelinerized = onelinerize(original)
self.assertEqual(capture_exec(original),
capture_exec(onelined),
msg="\n\nOnelined: "+onelined)
capture_exec(onelinerized),
msg="\n\nOnelined: " + onelinerized)
return new_test

class FakeStdin(object):
Expand Down Expand Up @@ -56,7 +56,7 @@ def capture_exec(code_string):
sys.stdin = old_stdin
return new_stdout.getvalue()

## Monkey-patch
# Monkey-patch
for subdir, dirs, files in os.walk(TEST_DIRECTORY):
for filename in files:
root, ext = os.path.splitext(filename)
Expand All @@ -67,4 +67,3 @@ def capture_exec(code_string):

if __name__ == '__main__':
unittest.main()

0 comments on commit 7f6a35e

Please sign in to comment.