This function accomplished little being a wrapper around parse to
concatenate a bunch of strings. While it served both __main__ and
test_hawkmoth, these actually have slightly different needs and the
difference increases when adding support for printing and testing
errors, respectively.
---
hawkmoth/__main__.py | 11 +++++++----
hawkmoth/parser.py | 9 ---------
test/test_hawkmoth.py | 11 +++++++++--
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/hawkmoth/__main__.py b/hawkmoth/__main__.py
index 8d237d7..1271772 100644
--- a/hawkmoth/__main__.py
+++ b/hawkmoth/__main__.py
@@ -10,7 +10,7 @@
import argparse
import sys
-from hawkmoth.parser import parse_to_string
+from hawkmoth.parser import parse
def main():
parser = argparse.ArgumentParser(prog='hawkmoth', description="""
@@ -31,8 +31,11 @@ def main():
help='Verbose output.')
args = parser.parse_args()
- comments = parse_to_string(args.file, args.verbose,
- compat=args.compat, clang=args.clang)
- sys.stdout.write(comments)
+ docs = parse(args.file, compat=args.compat, clang=args.clang)
+
+ for (doc, meta) in docs:
+ if args.verbose:
+ print('# {}'.format(meta))
+ print(doc)
main()
diff --git a/hawkmoth/parser.py b/hawkmoth/parser.py
index 5f2509b..ecb0d24 100644
--- a/hawkmoth/parser.py
+++ b/hawkmoth/parser.py
@@ -271,12 +271,3 @@ def parse(filename, **options):
result.sort(key=lambda r: r[1]['line'])
return result
-
-def parse_to_string(filename, verbose, **options):
- s = ''
- comments = parse(filename, **options)
- for (comment, meta) in comments:
- if verbose:
- s += ('# ' + str(meta) + '\n')
- s += comment + '\n'
- return s
diff --git a/test/test_hawkmoth.py b/test/test_hawkmoth.py
index 84101c3..07c2c14 100755
--- a/test/test_hawkmoth.py
+++ b/test/test_hawkmoth.py
@@ -6,10 +6,17 @@
import unittest
import testenv
-from hawkmoth.parser import parse_to_string
+from hawkmoth.parser import parse
def _get_output(input_filename, **options):
- return parse_to_string(input_filename, False, **options)
+ docs_str = ''
+
+ docs = parse(input_filename, **options)
+
+ for (doc, meta) in docs:
+ docs_str += doc + '\n'
+
+ return docs_str
def _get_expected(input_filename, **options):
return testenv.read_file(input_filename, ext='rst')
--
2.21.0