Merge pull request #11 from catseye/develop-0.13
Develop 0.13
Chris Pressey authored 2 years ago
GitHub committed 2 years ago
0 | 0 | History |
1 | 1 | ======= |
2 | ||
3 | Version 0.13 "Merchandise Mart": | |
4 | ||
5 | * Use `ArgumentParser` instead of `OptionParser` internally. | |
6 | * `--substring-error` is now the default behaviour, and if this | |
7 | option is given, it will be ignored. After a long time | |
8 | considering the problem, we finally determined that it does | |
9 | not make sense to insist that different implementations | |
10 | produce the exact same error message. | |
11 | * `--verbose` option now prints out commands for each test as it | |
12 | is run. | |
13 | * Added conventional `--version` option. | |
14 | * Planned to be the last 0.x series release before 1.0. | |
15 | * Added `setup.py` so that Falderal can be treated as a Python | |
16 | package. | |
2 | 17 | |
3 | 18 | Version 0.12 "Schoenhofen Brewery": |
4 | 19 |
0 | 0 | Falderal |
1 | 1 | ======== |
2 | 2 | |
3 | Version 0.12 "Schoenhofen Brewery" | |
3 | Version 0.13 "Merchandise Mart" | |
4 | 4 | |
5 | 5 | This is the reference distribution of Falderal, a file format for literate |
6 | 6 | test suites. What sets Falderal apart from most other test frameworks is |
15 | 15 | * being embedded in Markdown documents |
16 | 16 | |
17 | 17 | Falderal in three words: "Doctests for DSLs". |
18 | ||
19 | If you're more interested in running the tools than learning about the format | |
20 | itself, skip down to [Implementation](#implementation). | |
18 | 21 | |
19 | 22 | Motivation |
20 | 23 | ---------- |
107 | 110 | [`doc/Falderal_Literate_Test_Format.markdown`](doc/Falderal_Literate_Test_Format.markdown). |
108 | 111 | (Note that this specification should not be expected to remain stable |
109 | 112 | through the 0.x version series.) There are other documents in there too. |
110 | * `bin/falderal` — the reference implementation of Falderal, written in | |
111 | Python and sometimes referred to as "py-falderal". It imports the | |
112 | sources in `src/falderal`. You don't need to install it; just add | |
113 | the `bin` directory of this distribution to your `$PATH`. This | |
114 | implementation is (somewhat) documented in `doc/py-falderal.markdown`. | |
113 | * `bin/falderal` — the reference implementation of Falderal. | |
114 | See "Implementation", below, for details. | |
115 | 115 | * `script` — miscellaneous small tools intended to be used in tests. |
116 | 116 | * `src` — source code for py-falderal. |
117 | 117 | * `tests` — a set of tests for Falderal itself. (Note that these are not |
119 | 119 | * `HISTORY.markdown` — changelog for releases of Falderal. |
120 | 120 | * `TODO.markdown` — areas where Falderal and its implementations could be |
121 | 121 | improved. |
122 | ||
123 | Implementation | |
124 | -------------- | |
125 | ||
126 | This distribution contains `falderal`, which is the reference implementation | |
127 | of Falderal, written in Python and sometimes referred to as "py-falderal". | |
128 | ||
129 | To use it, you can clone this repository and run it as `bin/falderal` | |
130 | from the directory of your clone, or you can put the `bin` directory | |
131 | on your executable search path, and run it as `falderal` anywhere. | |
132 | ||
133 | Or you can install it using `pip`: | |
134 | ||
135 | pip install -e Falderal==0.13 | |
136 | ||
137 | (Depending on your needs, you may wish to establish a virtual environment | |
138 | first. Describing how to do so is outside the scope of this document.) | |
139 | ||
140 | The implementation is (somewhat) documented in `doc/py-falderal.markdown`. | |
122 | 141 | |
123 | 142 | Development |
124 | 143 | ----------- |
0 | import setuptools | |
1 | ||
2 | ||
3 | with open("README.markdown", "r") as fh: | |
4 | long_description = fh.read() | |
5 | ||
6 | setuptools.setup( | |
7 | name='Falderal', | |
8 | version='0.13', | |
9 | description='Definition of, and tools for using, the Falderal literate testing format', | |
10 | long_description=long_description, | |
11 | long_description_content_type="text/markdown", | |
12 | author='Chris Pressey', | |
13 | author_email='packages@catseye.tc', | |
14 | url='https://catseye.tc/node/Falderal', | |
15 | packages=['falderal'], | |
16 | package_dir={'': 'src'}, | |
17 | scripts=['bin/falderal'], | |
18 | classifiers=[ | |
19 | "Development Status :: 4 - Beta", | |
20 | "Intended Audience :: Developers", | |
21 | "License :: OSI Approved :: BSD License", | |
22 | "Operating System :: OS Independent", | |
23 | "Programming Language :: Python :: 2.7", | |
24 | "Programming Language :: Python :: 3", | |
25 | "Topic :: Software Development :: Testing", | |
26 | ], | |
27 | ) |
1 | 1 | Usage: falderal [<option>...] <filename.markdown>... |
2 | 2 | """ |
3 | 3 | |
4 | from optparse import OptionParser | |
4 | from argparse import ArgumentParser | |
5 | 5 | import sys |
6 | 6 | |
7 | 7 | from falderal.objects import Document, FalderalSyntaxError |
16 | 16 | ##### Main ##### |
17 | 17 | |
18 | 18 | def main(args): |
19 | parser = OptionParser() | |
20 | parser.add_option("-b", "--substring-error", | |
21 | action="store_true", default=False, | |
22 | help="match expected errors as substrings") | |
23 | parser.add_option("--cavalier", | |
24 | action="store_true", default=False, | |
25 | help="don't perform sanity linting before running tests") | |
26 | parser.add_option("-d", "--dump", | |
27 | action="store_true", default=False, | |
28 | help="print out info about parsed tests, don't run them") | |
29 | parser.add_option("-v", "--verbose", | |
30 | action="store_true", default=False, | |
31 | help="print out info about each test as it is run") | |
19 | argparser = ArgumentParser() | |
20 | argparser.add_argument('input_files', nargs='+', metavar='FILENAME', type=str, | |
21 | help='Falderal files containing the tests to use') | |
22 | argparser.add_argument("-b", "--substring-error", | |
23 | action="store_true", default=False, | |
24 | help="no effect (provided for backwards compatibility)") | |
25 | argparser.add_argument("--cavalier", | |
26 | action="store_true", default=False, | |
27 | help="don't perform sanity linting before running tests") | |
28 | argparser.add_argument("-d", "--dump", | |
29 | action="store_true", default=False, | |
30 | help="print out info about parsed tests, don't run them") | |
31 | argparser.add_argument("-v", "--verbose", | |
32 | action="store_true", default=False, | |
33 | help="print out info about each test as it is run") | |
34 | argparser.add_argument('--version', action='version', version="%(prog)s 0.13") | |
32 | 35 | |
33 | (options, args) = parser.parse_args(args[1:]) | |
36 | options = argparser.parse_args(args[1:]) | |
37 | ||
38 | if not options.substring_error: | |
39 | if options.verbose: | |
40 | print("NOTE: --substring-error is now default, option has no effect") | |
41 | options.substring_error = True | |
34 | 42 | |
35 | 43 | # load Documents and create Falderal Tests from them |
36 | 44 | documents = [] |
37 | 45 | functionalities = {} |
38 | 46 | tests = [] |
39 | 47 | try: |
40 | for filename in args: | |
48 | for filename in options.input_files: | |
41 | 49 | documents.append(Document.load(filename)) |
42 | 50 | for document in documents: |
43 | 51 | tests += document.extract_tests(functionalities) |
524 | 524 | def __init__(self): |
525 | 525 | pass |
526 | 526 | |
527 | def run(self, body=None, input=None): | |
527 | def run(self, body=None, input=None, verbose=False): | |
528 | 528 | """Returns the RunResult of running this implementation on the |
529 | 529 | given test body and input. |
530 | 530 | |
547 | 547 | def __str__(self): |
548 | 548 | return u'callable "%r"' % self.callable |
549 | 549 | |
550 | def run(self, body=None, input=None): | |
550 | def run(self, body=None, input=None, verbose=False): | |
551 | 551 | try: |
552 | 552 | result = self.callable(body, input) |
553 | 553 | return OutputOutcome(result) |
573 | 573 | `value`, but make sure `value` is properly shell-escaped first.""" |
574 | 574 | return command.replace(var_name, shlex_quote(value)) |
575 | 575 | |
576 | def run(self, body=None, input=None): | |
576 | def run(self, body=None, input=None, verbose=False): | |
577 | 577 | # first, expand all known variables in the command, using subst(). |
578 | 578 | test_filename = None |
579 | 579 | output_filename = None |
623 | 623 | os.close(fd) |
624 | 624 | # replace all occurrences in command |
625 | 625 | command = self.subst(command, '%(output-file)', output_filename) |
626 | ||
627 | if verbose: | |
628 | print(self, command) | |
626 | 629 | |
627 | 630 | # subshell the command and return the output |
628 | 631 | pipe = Popen(command, shell=True, |
717 | 720 | """ |
718 | 721 | results = [] |
719 | 722 | for implementation in self.functionality.implementations: |
720 | result = implementation.run(body=self.body, input=self.input) | |
723 | result = implementation.run( | |
724 | body=self.body, input=self.input, verbose=options.verbose | |
725 | ) | |
721 | 726 | if self.judge(result, options): |
722 | 727 | results.append(Success(self, implementation)) |
723 | 728 | else: |