PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_paginator.py

http://github.com/hyde/hyde
Python | 129 lines | 110 code | 13 blank | 6 comment | 5 complexity | 615c2c62487208ce855bcf24a39cef55 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2"""
  3Use nose
  4`$ pip install nose`
  5`$ nosetests`
  6"""
  7from textwrap import dedent
  8
  9from hyde.generator import Generator
 10from hyde.site import Site
 11
 12from fswrap import File
 13
 14TEST_SITE = File(__file__).parent.parent.child_folder('_test')
 15
 16class TestPaginator(object):
 17
 18    def setUp(self):
 19        TEST_SITE.make()
 20        TEST_SITE.parent.child_folder(
 21                  'sites/test_paginator').copy_contents_to(TEST_SITE)
 22        self.s = Site(TEST_SITE)
 23        self.deploy = TEST_SITE.child_folder('deploy')
 24
 25        self.gen = Generator(self.s)
 26        self.gen.load_site_if_needed()
 27        self.gen.load_template_if_needed()
 28        self.gen.generate_all()
 29
 30
 31    def tearDown(self):
 32        TEST_SITE.delete()
 33
 34
 35    def test_pages_of_one(self):
 36        pages = ['pages_of_one.txt', 'page2/pages_of_one.txt',
 37                    'page3/pages_of_one.txt', 'page4/pages_of_one.txt']
 38        files = [File(self.deploy.child(p)) for p in pages]
 39        for f in files:
 40            assert f.exists
 41
 42        page5 = File(self.deploy.child('page5/pages_of_one.txt'))
 43        assert not page5.exists
 44
 45
 46    def test_pages_of_one_content(self):
 47        expected_page1_content = dedent('''\
 48            Another Sad Post
 49
 50            /page2/pages_of_one.txt''')
 51        expected_page2_content = dedent('''\
 52            A Happy Post
 53            /pages_of_one.txt
 54            /page3/pages_of_one.txt''')
 55        expected_page3_content = dedent('''\
 56            An Angry Post
 57            /page2/pages_of_one.txt
 58            /page4/pages_of_one.txt''')
 59        expected_page4_content = dedent('''\
 60            A Sad Post
 61            /page3/pages_of_one.txt
 62            ''')
 63
 64        page1 = self.deploy.child('pages_of_one.txt')
 65        content = File(page1).read_all()
 66        assert expected_page1_content == content
 67
 68        page2 = self.deploy.child('page2/pages_of_one.txt')
 69        content = File(page2).read_all()
 70        assert expected_page2_content == content
 71
 72        page3 = self.deploy.child('page3/pages_of_one.txt')
 73        content = File(page3).read_all()
 74        assert expected_page3_content == content
 75
 76        page4 = self.deploy.child('page4/pages_of_one.txt')
 77        content = File(page4).read_all()
 78        assert expected_page4_content == content
 79
 80
 81    def test_pages_of_ten(self):
 82        page1 = self.deploy.child('pages_of_ten.txt')
 83        page2 = self.deploy.child('page2/pages_of_ten.txt')
 84
 85        assert File(page1).exists
 86        assert not File(page2).exists
 87
 88
 89    def test_pages_of_ten_depends(self):
 90        depends = self.gen.deps['pages_of_ten.txt']
 91
 92        assert depends
 93        assert len(depends) == 4
 94        assert 'blog/sad-post.html' in depends
 95        assert 'blog/another-sad-post.html' in depends
 96        assert 'blog/angry-post.html' in depends
 97        assert 'blog/happy-post.html' in depends
 98
 99
100    def test_pages_of_ten_content(self):
101        expected_content = dedent('''\
102            Another Sad Post
103            A Happy Post
104            An Angry Post
105            A Sad Post
106            ''')
107
108        page = self.deploy.child('pages_of_ten.txt')
109        content = File(page).read_all()
110        assert expected_content == content
111
112
113    def test_pages_of_one_depends(self):
114        depends = self.gen.deps['pages_of_one.txt']
115
116        assert depends
117        assert len(depends) == 4
118        assert 'blog/sad-post.html' in depends
119        assert 'blog/another-sad-post.html' in depends
120        assert 'blog/angry-post.html' in depends
121        assert 'blog/happy-post.html' in depends
122
123
124    def test_custom_file_pattern(self):
125        page1 = self.deploy.child('custom_file_pattern.txt')
126        page2 = self.deploy.child('custom_file_pattern-2.txt')
127
128        assert File(page1).exists
129        assert File(page2).exists