Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
872 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sys | ||
from optparse import OptionParser | ||
|
||
try: | ||
from coverage import coverage | ||
except ImportError: | ||
coverage = None | ||
|
||
parser = OptionParser() | ||
parser.add_option('-v', '--verbose', action='store_true', | ||
help='Be more verbose') | ||
if coverage: | ||
parser.add_option('-c', '--coverage', action='store_true', | ||
help='Measure code coverage') | ||
|
||
options, args = parser.parse_args() | ||
if args: | ||
parser.print_help() | ||
sys.exit(2) | ||
|
||
if coverage and options.coverage: | ||
cov = coverage() | ||
cov.start() | ||
|
||
# Import the Stango code down here to make coverage count the importing, too | ||
import stango.tests | ||
result = stango.tests.run(options.verbose) | ||
|
||
if result.wasSuccessful() and options.coverage: | ||
exclude = [ | ||
'stango.tests', | ||
'stango.autoreload', | ||
] | ||
|
||
def include_module(name): | ||
# exclude test code and stango.autoreload which is not testable | ||
for prefix in ['stango.tests', 'stango.autoreload']: | ||
if name.startswith(prefix): | ||
return False | ||
return name.startswith('stango') | ||
|
||
cov.stop() | ||
modules = [ | ||
module for name, module in sys.modules.items() | ||
if include_module(name) | ||
] | ||
cov.report(modules, file=sys.stdout) | ||
cov.erase() |
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
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
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,65 @@ | ||
from datetime import datetime | ||
import os | ||
import shutil | ||
import sys | ||
import unittest | ||
|
||
class StangoTestCase(unittest.TestCase): | ||
def setup(self): | ||
pass | ||
|
||
def teardown(self): | ||
pass | ||
|
||
def eq(self, a, b): | ||
return self.assertEqual(a, b) | ||
|
||
def assert_raises(self, exc_class, func, *args, **kwargs): | ||
'''Like assertRaises() but returns the exception''' | ||
try: | ||
func(*args, **kwargs) | ||
except exc_class as exc: | ||
return exc | ||
else: | ||
raise AssertionError('%s was not raised' % exc_class.__name__) | ||
|
||
def tempdir(self): | ||
path = os.path.join('tmp', self.id()) | ||
if os.path.exists(path): | ||
shutil.rmtree(path) | ||
os.makedirs(path) | ||
return path | ||
|
||
|
||
# Don't override these in test code | ||
|
||
def setUp(self): | ||
dirpath = os.path.dirname(__file__) | ||
self.template_path = os.path.join(dirpath, 'templates') | ||
self.data_path = os.path.relpath(os.path.join(dirpath, 'data')) | ||
self.setup() | ||
|
||
def tearDown(self): | ||
self.teardown() | ||
|
||
|
||
def make_suite(cls): | ||
return unittest.TestLoader().loadTestsFromTestCase(cls) | ||
|
||
|
||
def suite(): | ||
from stango.tests import \ | ||
test_files, test_generate, test_main, test_manager, test_serve, \ | ||
test_views | ||
suite = unittest.TestSuite() | ||
suite.addTest(test_files.suite()) | ||
suite.addTest(test_generate.suite()) | ||
suite.addTest(test_main.suite()) | ||
suite.addTest(test_manager.suite()) | ||
suite.addTest(test_serve.suite()) | ||
suite.addTest(test_views.suite()) | ||
return suite | ||
|
||
|
||
def run(verbose=False): | ||
return unittest.TextTestRunner(verbosity=(2 if verbose else 1)).run(suite()) |
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 @@ | ||
This is a test file |
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 @@ | ||
This is also a test file |
Binary file not shown.
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 @@ | ||
value is: {{ value }} |
Oops, something went wrong.