-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use metaclass for test generation, works way better for test discovery.
Test - naming, bikeshedding.
- Loading branch information
Showing
4 changed files
with
66 additions
and
54 deletions.
There are no files selected for viewing
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 @@ | ||
import unittest | ||
|
||
if __name__ == '__main__': | ||
|
||
# use the default shared TestLoader instance | ||
test_loader = unittest.defaultTestLoader | ||
|
||
# use the basic test runner that outputs to sys.stderr | ||
test_runner = unittest.TextTestRunner() | ||
|
||
# automatically discover all tests in the current dir of the form test*.py | ||
# NOTE: only works for python 2.7 and later | ||
test_suite = test_loader.discover('.') | ||
|
||
# run the test suite | ||
test_runner.run(test_suite) |
File renamed without changes.
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,50 @@ | ||
""" | ||
Check if shoebot can create files in all it's different output formats | ||
and that none are zero bytes long. | ||
""" | ||
|
||
import tempfile | ||
import unittest | ||
|
||
from os import stat, unlink | ||
from os.path import exists | ||
|
||
import shoebot | ||
|
||
from shoebot.core import CairoCanvas, CairoImageSink | ||
from shoebot.data import BezierPath | ||
from shoebot.grammar import NodeBot | ||
|
||
|
||
FORMATS = ["png", "ps", "pdf", "svg"] | ||
BOT_CODE = "background(0)" | ||
|
||
def run_shoebot_code(code, outputfile): | ||
bot = shoebot.create_bot(outputfile=outputfile) | ||
bot.run(code) | ||
return outputfile | ||
|
||
|
||
class TestFileOutputMeta(type): | ||
def __new__(mcs, name, bases, dct): | ||
def create_output_test(fmt, name): | ||
def test(self): | ||
h, fn = tempfile.mkstemp(suffix=".%s" % fmt) | ||
run_shoebot_code(BOT_CODE, outputfile=fn) | ||
self.assertTrue(exists(fn), "%s was not created" % fn) | ||
size_not_zero = stat(fn).st_size != 0 | ||
self.assertTrue(size_not_zero, "%s is zero bytes." % fn) | ||
unlink(fn) | ||
return test | ||
|
||
for fmt in FORMATS: | ||
test_name = 'test_create_' + fmt | ||
dct[test_name] = create_output_test(fmt, name) | ||
|
||
return type.__new__(mcs, name, bases, dct) | ||
|
||
class TestSequence(unittest.TestCase): | ||
__metaclass__ = TestFileOutputMeta | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |