Browse Source

Merge pull request #35 from denarced/master

Simplify code_prep.split_line, fix it's unit test.
pull/36/head
Chris 10 years ago
parent
commit
cf6d1b9e42
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
variable, instruction = line.split('=', 1)
return variable.strip(), instruction.strip()
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