8000 Add option to not generate yaml file · gui199/python-readability@b04f752 · GitHub
[go: up one dir, main page]

Skip to content

Commit b04f752

Browse files
jcharummitechie
authored andcommitted
Add option to not generate yaml file
Sometimes you just want to generate the data files without the YAML specification. This change lets you do that. In doing so, I switched to use the argparse module for argument parsing. Conflicts: src/tests/gen_test.py
1 parent c21f00b commit b04f752

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

src/tests/gen_test.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
and construct a new test case.
55
66
"""
7+
import argparse
78
import errno
89
import os
910
import 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

6562
def 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

Comments
 (0)
0