Exemplo n.º 1
0
 def test_node_injector(self):
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     site = settings.CONTEXT['site']
     blog_node = site.find_node(TEST_SITE.child_folder('content/blog'))
     self.generator.pre_process(site)
     for post in site.walk_pages():
         assert post.blog_node
         assert post.blog_node == blog_node
Exemplo n.º 2
0
 def test_categories(self):
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     context = settings.CONTEXT
     site = context['site']
     self.generator.pre_process(site)
     assert context['categories']
     assert len(context['categories']) == 4
     assert len(context['categories']['wishes']) == 3
     blog_node = site.find_node(TEST_SITE.child_folder('content/blog'))
     assert context['categories'] == blog_node.categories
Exemplo n.º 3
0
 def test_process_page_rendering(self):
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     source = File(TEST_ROOT.child("test_src.html"))
     self.site.refresh()
     self.site.monitor(self.queue)
     t = Thread(target=self.checker,
                     kwargs={"asserter":self.assert_valid_html})
     t.start()
     source.copy_to(self.site.content_folder.child("test_render.html"))
     t.join()
     assert self.exception_queue.empty()
Exemplo n.º 4
0
 def test_underscored_pages_are_not_rendered(self):
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     source = File(TEST_ROOT.child("test_src.html"))
     target = File(self.site.content_folder.child("_test.html"))
     self.site.refresh()
     self.site.monitor(self.queue)
     t = Thread(target=self.checker,
                     kwargs={"asserter":self.assert_layout_not_rendered})
     t.start()
     source.copy_to(target)
     t.join()
     target.delete()
     assert self.exception_queue.empty()
Exemplo n.º 5
0
 def test_recent_posts(self):
     site = SiteInfo(settings, TEST_SITE.path)
     site.refresh()
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     self.generator.pre_process(site)
     actual_resource = site.find_resource(
         File(site.content_folder.child('recent_posts.html')))
     self.generator.process(actual_resource)
     expected_text = File(
         TEST_ROOT.child("recent_posts_dest.html")).read_all()
     actual_text = actual_resource.temp_file.read_all()
     if ORIGINAL_PRE_PROCESSORS:
         settings.SITE_PRE_PROCESSORS = ORIGINAL_PRE_PROCESSORS
     assert_html_equals(expected_text, actual_text)
Exemplo n.º 6
0
    def test_categories(self):
        self.generator = Generator(TEST_SITE.path)
        self.generator.build_siteinfo()
        context = settings.CONTEXT
        site = context['site']
        self.generator.pre_process(site)
        blog_node = site.find_node(TEST_SITE.child_folder('content/blog'))
        assert hasattr(blog_node, 'categories')
        assert len(blog_node.categories) == 4
        found = False
        for category in blog_node.categories:
            if category['name'] == 'wishes':
                found = True
                assert len(category['posts']) == 3

        if not found:
            assert (False, "Category *wishes* not found")
Exemplo n.º 7
0
 def test_process_css_with_templates(self):
     original_MP = settings.MEDIA_PROCESSORS
     original_site = settings.SITE_ROOT
     settings.MEDIA_PROCESSORS = {"*":{".css":
     ('hydeengine.media_processors.TemplateProcessor',)}}
     settings.SITE_ROOT = "www.hyde-test.bogus/"
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     source = File(TEST_ROOT.child("test_src.css"))
     self.site.refresh()
     self.site.monitor(self.queue)
     t = Thread(target=self.checker,
                     kwargs={"asserter":self.assert_valid_css})
     t.start()
     source.copy_to(self.site.media_folder.child("test.css"))
     t.join()
     settings.MEDIA_PROCESSORS = original_MP
     settings.SITE_ROOT = original_site
     assert self.exception_queue.empty()
Exemplo n.º 8
0
    def test_textile(self):
        try:
            import textile
        except ImportError:
            textile = False
            print "Textile not found, skipping unit tests"

        if textile:
            self.generator = Generator(TEST_SITE.path)
            self.generator.build_siteinfo()
            source = File(TEST_ROOT.child("src_test_textile.html"))
            self.site.refresh()
            self.site.monitor(self.queue)
            t = Thread(target=self.checker,
                            kwargs={"asserter":self.assert_valid_textile})
            t.start()
            target = File(self.site.content_folder.child("test_textile.html"))
            source.copy_to(target)
            t.join()
            target.delete()
            assert self.exception_queue.empty()
Exemplo n.º 9
0
 def test_render_direct(self):
     render_folder = TEST_SITE.child_folder('content/render')
     render_folder.make()
     template_folder = TEST_SITE.child_folder('layout')
     template_folder.make()
     File(TEST_ROOT.child("render_tag/template.html")).copy_to(
         template_folder.child('render.html'))
     source = File(
         TEST_ROOT.child("render_tag/source.html")).copy_to(render_folder)
     site = SiteInfo(settings, TEST_SITE.path)
     site.refresh()
     self.generator = Generator(TEST_SITE.path)
     self.generator.build_siteinfo()
     self.generator.pre_process(site)
     actual_resource = site.find_resource(source)
     self.generator.process(actual_resource)
     expected_text = File(
         TEST_ROOT.child("render_tag/dest.html")).read_all()
     actual_text = actual_resource.temp_file.read_all()
     if ORIGINAL_PRE_PROCESSORS:
         settings.SITE_PRE_PROCESSORS = ORIGINAL_PRE_PROCESSORS
     assert_html_equals(expected_text, actual_text)
Exemplo n.º 10
0
    def test_folder_flattener(self):
        settings.MEDIA_PROCESSORS = {}
        settings.SITE_POST_PROCESSORS = {
            "blog": {
                "hydeengine.site_post_processors.FolderFlattener": {
                    'remove_processed_folders': True,
                    'pattern': "*.html"
                }
            }
        }

        self.generator = Generator(TEST_SITE.path)
        self.generator.generate()

        blog = Folder(settings.DEPLOY_DIR).child_folder("blog")

        class TestFlattener:
            def __init__(self):
                self.files = []

            def visit_folder(self, folder):
                assert folder.name in ("blog")

            def visit_file(self, a_file):
                self.files.append(a_file.name)

        tester = TestFlattener()
        blog.list(tester)
        blog_src = Folder(settings.CONTENT_DIR).child_folder("blog")

        class VerifyFlattener:
            @staticmethod
            def visit_file(a_file):
                try:
                    tester.files.index(a_file.name)
                except:
                    assert False

        blog_src.walk(VerifyFlattener)
Exemplo n.º 11
0
 def dopost(self, site):
     Generator(self.site_path).generate()
Exemplo n.º 12
0
def main(argv):

    parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 0.4")
    parser.add_option("-s",
                      "--sitepath",
                      dest="site_path",
                      help="Change the path of the site folder.")
    parser.add_option("-i",
                      "--init",
                      action='store_true',
                      dest="init",
                      default=False,
                      help="Create a new hyde site.")
    parser.add_option("-f",
                      "--force",
                      action='store_true',
                      dest="force_init",
                      default=False,
                      help="")
    parser.add_option("-t",
                      "--template",
                      dest="template",
                      help="Choose which template you want to use.")
    parser.add_option("-g",
                      "--generate",
                      action="store_true",
                      dest="generate",
                      default=False,
                      help="Generate the source for your hyde site.")
    parser.add_option("-k",
                      "--keep_watching",
                      action="store_true",
                      dest="keep_watching",
                      default=False,
                      help="Start monitoring the source folder for changes.")
    parser.add_option("-d",
                      "--deploy_to",
                      dest="deploy_to",
                      help="Change the path of the deploy folder.")
    parser.add_option("-w",
                      "--webserve",
                      action="store_true",
                      dest="webserve",
                      default=False,
                      help="Start an instance of the CherryPy webserver.")
    parser.add_option("-p",
                      "--port",
                      dest="port",
                      default=8080,
                      type='int',
                      help="Port webserver should listen on (8080).")
    parser.add_option("-a",
                      "--address",
                      dest="address",
                      default='localhost',
                      help="Address webserver should listen on (localhost).")

    (options, args) = parser.parse_args()

    if len(args):
        parser.error("Unexpected arguments encountered.")

    if not options.site_path:
        options.site_path = os.getcwdu()

    if options.deploy_to:
        options.deploy_to = os.path.abspath(options.deploy_to)

    if options.init:
        initializer = Initializer(options.site_path)
        initializer.initialize(PROG_ROOT, options.template, options.force_init)

    generator = None
    server = None

    def quit(*args, **kwargs):
        if server and server.alive:
            server.quit()
        if generator:
            generator.quit()

    if options.generate:
        generator = Generator(options.site_path)
        generator.generate(options.deploy_to, options.keep_watching, quit)

    if options.webserve:
        server = Server(options.site_path,
                        address=options.address,
                        port=options.port)
        server.serve(options.deploy_to, quit)

    if ((options.generate and options.keep_watching) or options.webserve):
        try:
            print "Letting the server and/or the generator do their thing..."
            if server:
                server.block()
                if generator:
                    generator.quit()
            elif generator:
                generator.block()
        except:
            print sys.exc_info()
            quit()

    if argv == []:
        print parser.format_option_help()