Browse Source

Simplify code_prep.split_line, fix it's unit test.

I presumed that the failing unit test was wrong and the previous implementation was working as it should.
pull/35/head
denarced 10 years ago
parent
commit
377b51700f
2 changed files with 4 additions and 7 deletions
  1. 7
      gooey/code_prep.py
  2. 4
      gooey/code_prep_unittest.py

7
gooey/code_prep.py

@ -38,11 +38,8 @@ def split_line(line):
# splits an assignment statement into varname and command strings
# in: "parser = ArgumentParser(description='Example Argparse Program')"
# out: "parser", "ArgumentParser(description='Example Argparse Program"
# take/dropwhile used to avoid splitting on multiple '=' signs
not_equal_sign = lambda x: x != '='
varname = ''.join(takewhile(not_equal_sign, line)).strip()
command = ''.join(dropwhile(not_equal_sign, line))[2:]
return varname, command
pieces = line.split('=', 1)
return pieces[0].strip(), ''.join(pieces[1:]).lstrip()
def update_parser_varname(new_varname, code):
# lines = source.split('\n')[1:]

4
gooey/code_prep_unittest.py

@ -8,7 +8,7 @@ class TestCodePrep(unittest.TestCase):
def test_split_line(self):
line = "parser = ArgumentParser(description='Example Argparse Program')"
self.assertEqual("parser", code_prep.split_line(line)[0])
self.assertEqual("= ArgumentParser(description='Example Argparse Program')", code_prep.split_line(line)[1])
self.assertEqual("ArgumentParser(description='Example Argparse Program')", code_prep.split_line(line)[1])
def test_update_parser_varname_assigns_new_name_to_parser_var(self):
line = ["parser = ArgumentParser(description='Example Argparse Program')"]
@ -54,4 +54,4 @@ parser.parse_args()
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
unittest.main()
Loading…
Cancel
Save