Commit c46fcb1f by Chris Jerdonek

Merge branch 'make-tests-subpackage' into 'development'.

The tests directory is now a subpackage.  This is more in line with
the recommended Python project file hierarchy as described here,
for example:

  http://as.ynchrono.us/2007/12/filesystem-structure-of-python-project_21.html

This should also make it easier to use the "use_2to3" with Distribute's test,
so that the directory containing the tests will also be converted to Python 3
when running `python setup.py test`.
parents aed894fd f9a5b3d2
...@@ -8,10 +8,14 @@ Provides test-related code that can be used by all tests. ...@@ -8,10 +8,14 @@ Provides test-related code that can be used by all tests.
import os import os
import examples import examples
import pystache
DATA_DIR = 'tests/data' _TESTS_DIR = os.path.dirname(pystache.tests.__file__)
DATA_DIR = os.path.join(_TESTS_DIR, 'data') # i.e. 'pystache/tests/data'.
EXAMPLES_DIR = os.path.dirname(examples.__file__) EXAMPLES_DIR = os.path.dirname(examples.__file__)
SPEC_TEST_DIR = os.path.join(os.path.dirname(pystache.__file__), '..', 'ext', 'spec', 'specs')
def get_data_path(file_name): def get_data_path(file_name):
......
...@@ -11,7 +11,7 @@ import unittest ...@@ -11,7 +11,7 @@ import unittest
from pystache.context import _NOT_FOUND from pystache.context import _NOT_FOUND
from pystache.context import _get_value from pystache.context import _get_value
from pystache.context import Context from pystache.context import Context
from tests.common import AssertIsMixin from pystache.tests.common import AssertIsMixin
class SimpleObject(object): class SimpleObject(object):
......
...@@ -12,8 +12,8 @@ from examples.unicode_output import UnicodeOutput ...@@ -12,8 +12,8 @@ from examples.unicode_output import UnicodeOutput
from examples.unicode_input import UnicodeInput from examples.unicode_input import UnicodeInput
from examples.nested_context import NestedContext from examples.nested_context import NestedContext
from pystache import Renderer from pystache import Renderer
from tests.common import EXAMPLES_DIR from pystache.tests.common import EXAMPLES_DIR
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin
class TestView(unittest.TestCase, AssertStringMixin): class TestView(unittest.TestCase, AssertStringMixin):
......
...@@ -9,14 +9,11 @@ import os ...@@ -9,14 +9,11 @@ import os
import sys import sys
import unittest import unittest
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin, DATA_DIR
from pystache import defaults from pystache import defaults
from pystache.loader import Loader from pystache.loader import Loader
DATA_DIR = 'tests/data'
class LoaderTests(unittest.TestCase, AssertStringMixin): class LoaderTests(unittest.TestCase, AssertStringMixin):
def test_init__extension(self): def test_init__extension(self):
......
# encoding: utf-8 # encoding: utf-8
""" """
Contains locator.py unit tests. Unit tests for locator.py.
""" """
...@@ -14,7 +14,7 @@ import unittest ...@@ -14,7 +14,7 @@ import unittest
from pystache.loader import Loader as Reader from pystache.loader import Loader as Reader
from pystache.locator import Locator from pystache.locator import Locator
from tests.common import DATA_DIR from pystache.tests.common import DATA_DIR
from data.views import SayHello from data.views import SayHello
......
...@@ -11,7 +11,7 @@ import unittest ...@@ -11,7 +11,7 @@ import unittest
from pystache.context import Context from pystache.context import Context
from pystache.parser import ParsingError from pystache.parser import ParsingError
from pystache.renderengine import RenderEngine from pystache.renderengine import RenderEngine
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin
class RenderEngineTestCase(unittest.TestCase): class RenderEngineTestCase(unittest.TestCase):
......
...@@ -15,9 +15,9 @@ from pystache import Renderer ...@@ -15,9 +15,9 @@ from pystache import Renderer
from pystache import TemplateSpec from pystache import TemplateSpec
from pystache.loader import Loader from pystache.loader import Loader
from tests.common import get_data_path from pystache.tests.common import get_data_path
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin
from tests.data.views import SayHello from pystache.tests.data.views import SayHello
class RendererInitTestCase(unittest.TestCase): class RendererInitTestCase(unittest.TestCase):
......
...@@ -8,8 +8,8 @@ from examples.lambdas import Lambdas ...@@ -8,8 +8,8 @@ from examples.lambdas import Lambdas
from examples.template_partial import TemplatePartial from examples.template_partial import TemplatePartial
from examples.simple import Simple from examples.simple import Simple
from tests.common import EXAMPLES_DIR from pystache.tests.common import EXAMPLES_DIR
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin
class TestSimple(unittest.TestCase, AssertStringMixin): class TestSimple(unittest.TestCase, AssertStringMixin):
......
...@@ -24,12 +24,16 @@ import glob ...@@ -24,12 +24,16 @@ import glob
import os.path import os.path
import unittest import unittest
import pystache
from pystache.renderer import Renderer from pystache.renderer import Renderer
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin, SPEC_TEST_DIR
root_path = os.path.join(os.path.dirname(__file__), '..', 'ext', 'spec', 'specs') spec_paths = glob.glob(os.path.join(SPEC_TEST_DIR, '*.json'))
spec_paths = glob.glob(os.path.join(root_path, '*.json'))
if len(spec_paths) == 0:
raise Exception("""Spec tests not found in: %s
Consult the README file on how to add the spec tests.""" % repr(SPEC_TEST_DIR))
# TODO: give this a name better than MustacheSpec. # TODO: give this a name better than MustacheSpec.
...@@ -92,6 +96,7 @@ def buildTest(testData, spec_filename): ...@@ -92,6 +96,7 @@ def buildTest(testData, spec_filename):
return test return test
for spec_path in spec_paths: for spec_path in spec_paths:
file_name = os.path.basename(spec_path) file_name = os.path.basename(spec_path)
......
...@@ -19,12 +19,12 @@ from pystache import TemplateSpec ...@@ -19,12 +19,12 @@ from pystache import TemplateSpec
from pystache.locator import Locator from pystache.locator import Locator
from pystache.loader import Loader from pystache.loader import Loader
from pystache.spec_loader import SpecLoader from pystache.spec_loader import SpecLoader
from tests.common import DATA_DIR from pystache.tests.common import DATA_DIR
from tests.common import EXAMPLES_DIR from pystache.tests.common import EXAMPLES_DIR
from tests.common import AssertIsMixin from pystache.tests.common import AssertIsMixin
from tests.common import AssertStringMixin from pystache.tests.common import AssertStringMixin
from tests.data.views import SampleView from pystache.tests.data.views import SampleView
from tests.data.views import NonAscii from pystache.tests.data.views import NonAscii
class Thing(object): class Thing(object):
...@@ -46,7 +46,8 @@ class ViewTestCase(unittest.TestCase, AssertStringMixin): ...@@ -46,7 +46,8 @@ class ViewTestCase(unittest.TestCase, AssertStringMixin):
self.assertRaises(IOError, renderer.render, view) self.assertRaises(IOError, renderer.render, view)
view.template_rel_directory = "../examples" # TODO: change this test to remove the following brittle line.
view.template_rel_directory = "../../examples"
actual = renderer.render(view) actual = renderer.render(view)
self.assertEquals(actual, "No tags...") self.assertEquals(actual, "No tags...")
......
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