Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from cirosantilli/add-tests
Automated tests. Thanks to @cirosantilli
- Loading branch information
Showing
19 changed files
with
436 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/inputs.tmp.md | ||
/all.tmp.md | ||
/config_local.py | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Concatenate all input output pairs into a single markdown file with format: | ||
# Path | ||
Input | ||
--- | ||
Output | ||
# Path2 | ||
... | ||
""" | ||
|
||
import itertools | ||
|
||
import md_testsuite | ||
|
||
output_path = u"all.tmp.md" | ||
|
||
assert [i for i in itertools.chain(xrange(2), xrange(2))] == [0, 1, 0, 1] | ||
|
||
with open(output_path, "w") as output_file: pass | ||
for path, input, output in itertools.chain(md_testsuite.io_iterator(), | ||
md_testsuite.io_iterator_all_engines()): | ||
with open(output_path, "a") as output_file: | ||
output_file.write("# {0}\n\n{1}\n\n---\n\n{2}\n\n".format(path, input, output)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This dict contains configurations which users may want to, or are required to personalize. | ||
# Some values can be omitted and have defaults set for them on `md_testsuite.py`. | ||
config = dict( | ||
|
||
# Required for GFM. | ||
# Generate token on GitHub website on Profile > Applications > Generate | ||
# Turn off all abilities by unchecking all boxes: none are necessary for markdown compilation. | ||
#gfm_oauth_token = '', | ||
|
||
# Listed methods will be excluded from the `run-tests.py` all tests invocation. | ||
# `[]` to run all engines. | ||
#run_all_disable = [], | ||
|
||
# Timeout in seconds. | ||
#timeout = 5 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
""" | ||
Shared functionality. | ||
""" | ||
|
||
import imp | ||
import os | ||
|
||
# Default config values here. | ||
config = dict( | ||
gfm_oauth_token = '', | ||
# GFM off by default because it is too slow. | ||
run_all_disable = ['gfm'], | ||
timeout = 5 | ||
) | ||
try: | ||
config_custom = imp.load_source('config_local', 'config_local.py').config | ||
config.update(config_custom) | ||
except IOError: | ||
# Config file not present. | ||
pass | ||
|
||
# Encoding of all out outputs when we can chose it, hopefully equal to most inputs. | ||
encoding = 'utf-8' | ||
in_ext = u".md" | ||
out_ext = u".out" | ||
test_dir = u"tests" | ||
engines_dir = os.path.join(test_dir, u"extensions") | ||
|
||
# Output UTF-8 by default. | ||
import sys | ||
reload(sys) | ||
sys.setdefaultencoding(encoding) | ||
|
||
def same_basename_on_parent(path): | ||
path_split = path.split(os.sep) | ||
return os.sep.join(path_split[0:-2] + [path_split[-1]]) | ||
|
||
def io_iterator(): | ||
""" | ||
Iterator over all input output pairs of the Original markdown, no engines. | ||
Each yield returns a 3-tuple `(path, input, output)` where: | ||
- `path` is the path of the test relative to the `test_dir` and without engine (`.md` or `.out`). | ||
- `input` and `output` are the content of the input and output files. | ||
""" | ||
for basename in sorted(os.listdir(test_dir)): | ||
input_path = os.path.join(test_dir, basename) | ||
if os.path.isfile(input_path): | ||
path_noext, ext = os.path.splitext(input_path) | ||
if ext == in_ext: | ||
with open(input_path, "r") as input_file: | ||
input = input_file.read().decode(encoding) | ||
output_path = path_noext + out_ext | ||
with open(output_path, "r") as output_file: | ||
output = output_file.read().decode(encoding) | ||
yield (path_noext[(len(test_dir)+1):], input, output) | ||
|
||
def io_iterator_engine(id): | ||
""" | ||
Iterator over all input output pairs of a given engine. | ||
Original markdown is not included. | ||
""" | ||
engine_dir = os.path.join(engines_dir, id) | ||
for basename in sorted(os.listdir(engine_dir)): | ||
input_path = os.path.join(engine_dir, basename) | ||
if os.path.isfile(input_path): | ||
path_noext, ext = os.path.splitext(input_path) | ||
if ext == in_ext: | ||
# Get input | ||
with open(input_path, "r") as input_file: | ||
input = input_file.read().decode(encoding) | ||
if not input: | ||
with open(same_basename_on_parent(input_path), "r") as input_file: | ||
input = input_file.read().decode(encoding) | ||
|
||
# Get output | ||
output_path = path_noext + out_ext | ||
if not os.path.exists(output_path): | ||
output_path = same_basename_on_parent(output_path) | ||
with open(output_path, "r") as output_file: | ||
output = output_file.read().decode(encoding) | ||
|
||
yield (path_noext[(len(test_dir)+1):], input, output) | ||
|
||
def get_engine_ids(): | ||
""" | ||
Returns a sorted list of ids of all supported engines | ||
based on the directories present under the engines directory. | ||
""" | ||
output = [] | ||
for basename in sorted(os.listdir(engines_dir)): | ||
path = os.path.join(engines_dir, basename) | ||
if os.path.isdir(path): | ||
output.append(basename) | ||
return output | ||
|
||
def io_iterator_all_engines(): | ||
""" | ||
Iterator over all input output pairs of a all engines | ||
Original markdown is not included. | ||
""" | ||
for id in get_engine_ids(): | ||
for io in io_iterator_engine(id): | ||
yield io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
beautifulsoup4==4.3.2 |
Oops, something went wrong.