Commit 0db07048 by Chris Jerdonek

Stubbed out a stand-alone script command.

The eventual goal is to have a test script that behaves well with tox.
Using a stand-alone test script that we control instead of an
out-of-the-box command-line script like nosetests or Distribute's test
should give us more flexibility in dealing with any idiosyncracies
that occur with tox.
parent eacbdb3b
# coding: utf-8
"""
This module provides a command to test pystache (unit tests, doctests, etc).
"""
import sys
# TODO: make nose unnecessary.
import nose
import pystache
def main(sys_argv):
# This does not work with the --with-doctest flag yet because of the
# following issue:
# https://github.com/nose-devs/nose/issues/383
nose.main(module=pystache)
if __name__=='__main__':
main(sys.argv)
......@@ -34,13 +34,20 @@ class LocatorTests(unittest.TestCase):
locator = Locator(extension=False)
self.assertTrue(locator.template_extension is False)
def _assert_paths(self, actual, expected):
"""
Assert that two paths are the same.
"""
self.assertEqual(actual, expected)
def test_get_object_directory(self):
locator = Locator()
obj = SayHello()
actual = locator.get_object_directory(obj)
self.assertEqual(actual, os.path.abspath(DATA_DIR))
self._assert_paths(actual, DATA_DIR)
def test_get_object_directory__not_hasattr_module(self):
locator = Locator()
......@@ -111,9 +118,9 @@ class LocatorTests(unittest.TestCase):
obj = SayHello()
actual = locator.find_object(search_dirs=[], obj=obj, file_name='sample_view.mustache')
expected = os.path.abspath(os.path.join(DATA_DIR, 'sample_view.mustache'))
expected = os.path.join(DATA_DIR, 'sample_view.mustache')
self.assertEqual(actual, expected)
self._assert_paths(actual, expected)
def test_find_object__none_file_name(self):
locator = Locator()
......@@ -121,7 +128,7 @@ class LocatorTests(unittest.TestCase):
obj = SayHello()
actual = locator.find_object(search_dirs=[], obj=obj)
expected = os.path.abspath(os.path.join(DATA_DIR, 'say_hello.mustache'))
expected = os.path.join(DATA_DIR, 'say_hello.mustache')
self.assertEqual(actual, expected)
......
......@@ -19,10 +19,8 @@ from pystache import TemplateSpec
from pystache.locator import Locator
from pystache.loader import Loader
from pystache.specloader import SpecLoader
from pystache.tests.common import DATA_DIR
from pystache.tests.common import EXAMPLES_DIR
from pystache.tests.common import AssertIsMixin
from pystache.tests.common import AssertStringMixin
from pystache.tests.common import DATA_DIR, EXAMPLES_DIR
from pystache.tests.common import AssertIsMixin, AssertStringMixin
from pystache.tests.data.views import SampleView
from pystache.tests.data.views import NonAscii
......@@ -358,6 +356,13 @@ class TemplateSpecTests(unittest.TestCase):
view.template_extension = 'txt'
self._assert_template_location(view, (None, 'sample_view.txt'))
def _assert_paths(self, actual, expected):
"""
Assert that two paths are the same.
"""
self.assertEqual(actual, expected)
def test_find__with_directory(self):
"""
Test _find() with a view that has a directory specified.
......@@ -370,9 +375,9 @@ class TemplateSpecTests(unittest.TestCase):
self.assertTrue(loader._find_relative(view)[0] is not None)
actual = loader._find(view)
expected = os.path.abspath(os.path.join(DATA_DIR, 'foo/bar.txt'))
expected = os.path.join(DATA_DIR, 'foo/bar.txt')
self.assertEqual(actual, expected)
self._assert_paths(actual, expected)
def test_find__without_directory(self):
"""
......@@ -385,9 +390,9 @@ class TemplateSpecTests(unittest.TestCase):
self.assertTrue(loader._find_relative(view)[0] is None)
actual = loader._find(view)
expected = os.path.abspath(os.path.join(DATA_DIR, 'sample_view.mustache'))
expected = os.path.join(DATA_DIR, 'sample_view.mustache')
self.assertEqual(actual, expected)
self._assert_paths(actual, expected)
def _assert_get_template(self, custom, expected):
loader = self._make_loader()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment