Ejemplo n.º 1
0
    def test_get_object_directory(self):
        locator = Locator()

        obj = SayHello()
        actual = locator.get_object_directory(obj)

        self.assertEquals(actual, os.path.abspath(DATA_DIR))
Ejemplo n.º 2
0
    def test_get_object_directory(self):
        locator = Locator()

        obj = SayHello()
        actual = locator.get_object_directory(obj)

        self._assert_paths(actual, DATA_DIR)
Ejemplo n.º 3
0
    def test_get_object_directory(self):
        locator = Locator()

        obj = SayHello()
        actual = locator.get_object_directory(obj)

        self._assert_paths(actual, DATA_DIR)
Ejemplo n.º 4
0
    def test_find_object__none_file_name(self):
        locator = Locator()

        obj = SayHello()

        actual = locator.find_object(search_dirs=[], obj=obj)
        expected = os.path.abspath(os.path.join(DATA_DIR, "say_hello.mustache"))

        self.assertEquals(actual, expected)
Ejemplo n.º 5
0
    def test_find_object(self):
        locator = Locator()

        obj = SayHello()

        actual = locator.find_object(search_dirs=[], obj=obj, file_name='sample_view.mustache')
        expected = os.path.join(DATA_DIR, 'sample_view.mustache')

        self._assert_paths(actual, expected)
Ejemplo n.º 6
0
    def test_get_object_directory(self):
        locator = Locator()

        reader = Reader()
        actual = locator.get_object_directory(reader)

        expected = os.path.join(os.path.dirname(__file__), os.pardir, 'pystache')

        self.assertEquals(os.path.normpath(actual), os.path.normpath(expected))
Ejemplo n.º 7
0
    def test_find_object__none_file_name(self):
        locator = Locator()

        obj = SayHello()

        actual = locator.find_object(search_dirs=[], obj=obj)
        expected = os.path.join(DATA_DIR, 'say_hello.mustache')

        self.assertEqual(actual, expected)
Ejemplo n.º 8
0
    def test_get_object_directory__not_hasattr_module(self):
        locator = Locator()

        obj = datetime(2000, 1, 1)
        self.assertFalse(hasattr(obj, "__module__"))
        self.assertEquals(locator.get_object_directory(obj), None)

        self.assertFalse(hasattr(None, "__module__"))
        self.assertEquals(locator.get_object_directory(None), None)
Ejemplo n.º 9
0
    def test_find_object(self):
        locator = Locator()

        obj = SayHello()

        actual = locator.find_object(search_dirs=[], obj=obj, file_name='sample_view.mustache')
        expected = os.path.join(DATA_DIR, 'sample_view.mustache')

        self._assert_paths(actual, expected)
Ejemplo n.º 10
0
    def test_get_object_directory__not_hasattr_module(self):
        locator = Locator()

        obj = datetime(2000, 1, 1)
        self.assertFalse(hasattr(obj, '__module__'))
        self.assertEqual(locator.get_object_directory(obj), None)

        self.assertFalse(hasattr(None, '__module__'))
        self.assertEqual(locator.get_object_directory(None), None)
Ejemplo n.º 11
0
    def test_find_object__none_object_directory(self):
        locator = Locator()

        obj = None
        self.assertEquals(None, locator.get_object_directory(obj))

        actual = locator.find_object(search_dirs=[DATA_DIR], obj=obj, file_name="say_hello.mustache")
        expected = os.path.join(DATA_DIR, "say_hello.mustache")

        self.assertEquals(actual, expected)
Ejemplo n.º 12
0
    def test_get_object_directory(self):
        locator = Locator()

        reader = Reader()
        actual = locator.get_object_directory(reader)

        expected = os.path.join(os.path.dirname(__file__), os.pardir,
                                'pystache')

        self.assertEquals(os.path.normpath(actual), os.path.normpath(expected))
Ejemplo n.º 13
0
    def test_init__extension(self):
        # Test the default value.
        locator = Locator()
        self.assertEqual(locator.template_extension, 'mustache')

        locator = Locator(extension='txt')
        self.assertEqual(locator.template_extension, 'txt')

        locator = Locator(extension=False)
        self.assertTrue(locator.template_extension is False)
Ejemplo n.º 14
0
    def test_find_object__none_object_directory(self):
        locator = Locator()

        obj = None
        self.assertEqual(None, locator.get_object_directory(obj))

        actual = locator.find_object(search_dirs=[DATA_DIR], obj=obj, file_name='say_hello.mustache')
        expected = os.path.join(DATA_DIR, 'say_hello.mustache')

        self.assertEqual(actual, expected)
Ejemplo n.º 15
0
    def test_make_template_name(self):
        """
        Test make_template_name().

        """
        locator = Locator()

        class FooBar(object):
            pass
        foo = FooBar()

        self.assertEqual(locator.make_template_name(foo), 'foo_bar')
Ejemplo n.º 16
0
    def test_make_template_name(self):
        """
        Test make_template_name().

        """
        locator = Locator()

        class FooBar(object):
            pass
        foo = FooBar()

        self.assertEqual(locator.make_template_name(foo), 'foo_bar')
Ejemplo n.º 17
0
    def test_locate_path__non_existent_template_fails(self):
        locator = Locator()

        self.assertRaises(IOError,
                          locator.locate_path,
                          'doesnt_exist',
                          search_dirs=[])
Ejemplo n.º 18
0
    def test_make_locator__default(self):
        renderer = Renderer()
        actual = renderer.make_locator()

        expected = Locator()

        self.assertEquals(type(actual), type(expected))
        self.assertEquals(actual.template_extension, expected.template_extension)
Ejemplo n.º 19
0
    def test_locate_path__precedence(self):
        """
        Test the order in which locate_path() searches directories.

        """
        locator = Locator()

        dir1 = DATA_DIR
        dir2 = os.path.join(DATA_DIR, 'locator')

        self.assertTrue(locator.locate_path('duplicate', search_dirs=[dir1]))
        self.assertTrue(locator.locate_path('duplicate', search_dirs=[dir2]))

        path = locator.locate_path('duplicate', search_dirs=[dir2, dir1])
        dirpath = os.path.dirname(path)
        dirname = os.path.split(dirpath)[-1]

        self.assertEquals(dirname, 'locator')
Ejemplo n.º 20
0
    def test_locate_path__precedence(self):
        """
        Test the order in which locate_path() searches directories.

        """
        locator = Locator()

        dir1 = DATA_DIR
        dir2 = os.path.join(DATA_DIR, 'locator')

        self.assertTrue(locator.locate_path('duplicate', search_dirs=[dir1]))
        self.assertTrue(locator.locate_path('duplicate', search_dirs=[dir2]))

        path = locator.locate_path('duplicate', search_dirs=[dir2, dir1])
        dirpath = os.path.dirname(path)
        dirname = os.path.split(dirpath)[-1]

        self.assertEquals(dirname, 'locator')
Ejemplo n.º 21
0
    def test_find_name__precedence(self):
        """
        Test the order in which find_name() searches directories.

        """
        locator = Locator()

        dir1 = DATA_DIR
        dir2 = LOCATOR_DATA_DIR

        self.assertTrue(locator.find_name(search_dirs=[dir1], template_name='duplicate'))
        self.assertTrue(locator.find_name(search_dirs=[dir2], template_name='duplicate'))

        path = locator.find_name(search_dirs=[dir2, dir1], template_name='duplicate')
        dirpath = os.path.dirname(path)
        dirname = os.path.split(dirpath)[-1]

        self.assertEqual(dirname, 'locator')
Ejemplo n.º 22
0
    def test_find_name__non_existent_template_fails(self):
        locator = Locator()

        self.assertException(
            LocatorNotFoundError,
            "File 'doesnt_exist.mustache' not found in dirs: []",
            locator.find_name,
            search_dirs=[],
            template_name='doesnt_exist')
Ejemplo n.º 23
0
    def test_find_name__precedence(self):
        """
        Test the order in which find_name() searches directories.

        """
        locator = Locator()

        dir1 = DATA_DIR
        dir2 = os.path.join(DATA_DIR, "locator")

        self.assert_(locator.find_name(search_dirs=[dir1], template_name="duplicate"))
        self.assert_(locator.find_name(search_dirs=[dir2], template_name="duplicate"))

        path = locator.find_name(search_dirs=[dir2, dir1], template_name="duplicate")
        dirpath = os.path.dirname(path)
        dirname = os.path.split(dirpath)[-1]

        self.assertEquals(dirname, "locator")
Ejemplo n.º 24
0
    def test_find_name__precedence(self):
        """
        Test the order in which find_name() searches directories.

        """
        locator = Locator()

        dir1 = DATA_DIR
        dir2 = LOCATOR_DATA_DIR

        self.assertTrue(locator.find_name(search_dirs=[dir1], template_name='duplicate'))
        self.assertTrue(locator.find_name(search_dirs=[dir2], template_name='duplicate'))

        path = locator.find_name(search_dirs=[dir2, dir1], template_name='duplicate')
        dirpath = os.path.dirname(path)
        dirname = os.path.split(dirpath)[-1]

        self.assertEqual(dirname, 'locator')
Ejemplo n.º 25
0
    def test_make_file_name(self):
        locator = Locator()

        locator.template_extension = 'bar'
        self.assertEqual(locator.make_file_name('foo'), 'foo.bar')

        locator.template_extension = False
        self.assertEqual(locator.make_file_name('foo'), 'foo')

        locator.template_extension = ''
        self.assertEqual(locator.make_file_name('foo'), 'foo.')
Ejemplo n.º 26
0
    def test_get_object_directory__not_hasattr_module(self):
        locator = Locator()

        # Previously, we used a genuine object -- a datetime instance --
        # because datetime instances did not have the __module__ attribute
        # in CPython.  See, for example--
        #
        #   http://bugs.python.org/issue15223
        #
        # However, since datetime instances do have the __module__ attribute
        # in PyPy, we needed to switch to something else once we added
        # support for PyPi.  This was so that our test runs would pass
        # in all systems.
        obj = "abc"
        self.assertFalse(hasattr(obj, '__module__'))
        self.assertEqual(locator.get_object_directory(obj), None)

        self.assertFalse(hasattr(None, '__module__'))
        self.assertEqual(locator.get_object_directory(None), None)
Ejemplo n.º 27
0
    def test_get_object_directory__not_hasattr_module(self):
        locator = Locator()

        # Previously, we used a genuine object -- a datetime instance --
        # because datetime instances did not have the __module__ attribute
        # in CPython.  See, for example--
        #
        #   http://bugs.python.org/issue15223
        #
        # However, since datetime instances do have the __module__ attribute
        # in PyPy, we needed to switch to something else once we added
        # support for PyPi.  This was so that our test runs would pass
        # in all systems.
        obj = "abc"
        self.assertFalse(hasattr(obj, '__module__'))
        self.assertEqual(locator.get_object_directory(obj), None)

        self.assertFalse(hasattr(None, '__module__'))
        self.assertEqual(locator.get_object_directory(None), None)
Ejemplo n.º 28
0
    def test_make_file_name(self):
        locator = Locator()

        locator.template_extension = 'bar'
        self.assertEqual(locator.make_file_name('foo'), 'foo.bar')

        locator.template_extension = False
        self.assertEqual(locator.make_file_name('foo'), 'foo')

        locator.template_extension = ''
        self.assertEqual(locator.make_file_name('foo'), 'foo.')
Ejemplo n.º 29
0
    def test_make_file_name(self):
        locator = Locator()

        locator.template_extension = "bar"
        self.assertEquals(locator.make_file_name("foo"), "foo.bar")

        locator.template_extension = False
        self.assertEquals(locator.make_file_name("foo"), "foo")

        locator.template_extension = ""
        self.assertEquals(locator.make_file_name("foo"), "foo.")
Ejemplo n.º 30
0
    def test_locate_path__using_list_of_paths(self):
        locator = Locator()
        path = locator.locate_path('simple',
                                   search_dirs=['doesnt_exist', 'examples'])

        self.assertTrue(path)
Ejemplo n.º 31
0
    def test_make_file_name__template_extension_argument(self):
        locator = Locator()

        self.assertEqual(locator.make_file_name('foo', template_extension='bar'), 'foo.bar')
Ejemplo n.º 32
0
    def test_locate_path__using_list_of_paths(self):
        locator = Locator()
        path = locator.locate_path('simple', search_dirs=['doesnt_exist', 'examples'])

        self.assertTrue(path)
Ejemplo n.º 33
0
    def test_locate_path(self):
        locator = Locator()
        path = locator.locate_path('simple', search_dirs=['examples'])

        self.assertEquals(os.path.basename(path), 'simple.mustache')
Ejemplo n.º 34
0
 def _make_locator(self):
     return Locator(extension=self.extension)
Ejemplo n.º 35
0
    def test_find_name__using_list_of_paths(self):
        locator = Locator()
        path = locator.find_name(search_dirs=[EXAMPLES_DIR, 'doesnt_exist'], template_name='simple')

        self.assertTrue(path)
Ejemplo n.º 36
0
    def test_find_file(self):
        locator = Locator()
        path = locator.find_file('template.txt', [LOCATOR_DATA_DIR])

        expected_path = os.path.join(LOCATOR_DATA_DIR, 'template.txt')
        self.assertEqual(path, expected_path)
Ejemplo n.º 37
0
    def test_find_name(self):
        locator = Locator()
        path = locator.find_name(search_dirs=[EXAMPLES_DIR], template_name='simple')

        self.assertEqual(os.path.basename(path), 'simple.mustache')
Ejemplo n.º 38
0
    def test_find_name__using_list_of_paths(self):
        locator = Locator()
        path = locator.find_name(search_dirs=["doesnt_exist", "examples"], template_name="simple")

        self.assert_(path)
Ejemplo n.º 39
0
    def test_make_file_name__template_extension_argument(self):
        locator = Locator()

        self.assertEquals(locator.make_file_name("foo", template_extension="bar"), "foo.bar")
Ejemplo n.º 40
0
    def test_find_name(self):
        locator = Locator()
        path = locator.find_name(search_dirs=[EXAMPLES_DIR], template_name='simple')

        self.assertEqual(os.path.basename(path), 'simple.mustache')
Ejemplo n.º 41
0
 def _locator(self):
     return Locator(search_dirs=DATA_DIR)
Ejemplo n.º 42
0
    def test_find_name__using_list_of_paths(self):
        locator = Locator()
        path = locator.find_name(search_dirs=[EXAMPLES_DIR, 'doesnt_exist'], template_name='simple')

        self.assertTrue(path)
Ejemplo n.º 43
0
    def test_find_name(self):
        locator = Locator()
        path = locator.find_name(search_dirs=["examples"], template_name="simple")

        self.assertEquals(os.path.basename(path), "simple.mustache")
Ejemplo n.º 44
0
    def test_find_file(self):
        locator = Locator()
        path = locator.find_file('template.txt', [LOCATOR_DATA_DIR])

        expected_path = os.path.join(LOCATOR_DATA_DIR, 'template.txt')
        self.assertEqual(path, expected_path)
Ejemplo n.º 45
0
    def test_make_file_name__template_extension_argument(self):
        locator = Locator()

        self.assertEqual(locator.make_file_name('foo', template_extension='bar'), 'foo.bar')
Ejemplo n.º 46
0
    def test_locate_path(self):
        locator = Locator()
        path = locator.locate_path('simple', search_dirs=['examples'])

        self.assertEquals(os.path.basename(path), 'simple.mustache')