44and construct a new test case.
55
66"""
7+ import argparse
78import errno
89import os
910import os .path
@@ -38,12 +39,13 @@ def write_file(test_name, suffix, data):
3839 f .write (data )
3940 return True
4041
41- def gen_test (url , test_name , test_description ):
42- spec_dict = {'url' : url , 'test_description' : test_description }
43- spec = yaml .dump (spec_dict , default_flow_style = False )
44- if not write_file (test_name , test .YAML_EXTENSION , spec ):
45- return False
4642
43+ def gen_test (url , test_name , test_description , gen_yaml = True ):
44+ if gen_yaml :
45+ spec_dict = {'url' : url , 'test_description' : test_description }
46+ spec = yaml .dump (spec_dict , default_flow_style = False )
47+ if not write_file (test_name , test .YAML_EXTENSION , spec ):
48+ return False
4749 orig = urllib2 .urlopen (url ).read ()
4850 if not write_file (test_name , test .ORIGINAL_SUFFIX , orig ):
4951 return False
@@ -55,21 +57,40 @@ def gen_test(url, test_name, test_description):
5557
5658 return True
5759
58- USAGE = '''
59- usage: %s <url> <test name> <test description>
60- '''
61-
62- def usage (prog_name ):
63- print (USAGE % prog_name )
60+ DESCRIPTION = 'Create a readability regression test case.'
6461
6562def main ():
66- if len (sys .argv ) != 4 :
67- usage (sys .argv [0 ])
68- return
69- url = sys .argv [1 ]
70- test_name = sys .argv [2 ]
71- test_description = sys .argv [3 ]
72- result = gen_test (url , test_name , test_description )
63+ parser = argparse .ArgumentParser (description = DESCRIPTION )
64+ parser .add_argument (
65+ '--no-yaml' ,
66+ dest = 'no_yaml' ,
67+ action = 'store_const' ,
68+ const = True ,
69+ default = False ,
70+ help = 'if set, no yaml file will be generated'
71+ )
72+ parser .add_argument (
73+ 'url' ,
74+ metavar = 'url' ,
75+ help = 'the url for which to generate a test'
76+ )
77+ parser .add_argument (
78+ 'test_name' ,
79+ metavar = 'test-name' ,
80+ help = 'the name of the test'
81+ )
82+ parser .add_argument (
83+ 'test_description' ,
84+ metavar = 'test-description' ,
85+ help = 'the description of the test'
86+ )
87+ args = parser .parse_args ()
88+ result = gen_test (
89+ args .url ,
90+ args .test_name ,
91+ args .test_description ,
92+ gen_yaml = not args .no_yaml
93+ )
7394 if not result :
7495 print ('test was not fully generated' )
7596
0 commit comments