def test_config(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) options = ObjectLike({ "source": None, "dest": None, "fork": True, "appcache": False, "debug": False, "pygments": False }) config = SiteConfig(options) #print >>sys.stderr, config["source"] assert config["source"] == join(pages_test_root,"web") assert config["appcache"] == False assert config["debug"] == False options = ObjectLike({ "source": None, "dest": None, "fork": True, "appcache": True, "debug": True, "pygments": False }) config = SiteConfig(options) #print >>sys.stderr, config["source"] assert config["source"] == join(pages_test_root,"web") assert config["appcache"] == True assert config["debug"] == True
def test_split(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) config = SiteConfig({}) file_contents = """\ function f() {} """ matter,content = config.split_matter_and_utf8_content(file_contents,{ "Content-Type": "text/javascript" }) assert matter["charset"] == "utf-8" file_contents = """\ --- --- .test {} """ matter,content = config.split_matter_and_utf8_content(file_contents,{ "Content-Type": "text/css" }) assert matter["charset"] == "utf-8" file_contents = """\ --- charset: iso8859-1 --- .test {} """ matter,content = config.split_matter_and_utf8_content(file_contents,{ "Content-Type": "text/css" }) assert matter["charset"] == "iso8859-1" file_contents = """\ --- --- """ matter,content = config.split_matter_and_utf8_content(file_contents,{ "Content-Type": "image/gif", "charset":False }) assert "charset" not in matter
def notest_fetch_content(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) config = SiteConfig({}) basedir = join(pages_test_root,"web") header = { "Content-Type": "text/javascript", "content": ["../resources/html5-patch.js","abc_shim.js"] } content = browsers[0].fetchContent(header,config,basedir) assert type(content) == unicode
def prep_site_config(rel_path,browser=None): from webpages import apply_site_dirs from webpages.config import SiteConfig shutil.rmtree(join(pages_test_root,"output"), ignore_errors=True) apply_site_dirs("",force_project_path=join(pages_test_root,rel_path)) config = SiteConfig({ "dest": join(pages_test_root,"output"), "browser": browser, }) return config
def test_split_matter_content(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) options, r = server_options_parser.parse_args(args=["--nofork"]) config = SiteConfig(options) header = { "Content-Type": "text/html", } content = None with open(abspath(join(site.PROJECT_DIR,"unicode.md")), "rb") as f: content = f.read() #expander = FileExpander(site.PROJECT_DIR,"unicode.md",config=config) #self.header,self.content,self.fetchContent = self._get_matter_and_content(relpath,header) header2,content2 = config.split_matter_and_utf8_content(content,header) assert type(content2) == unicode assert "test" in header2 assert type(header2["test"]) == unicode
def test_exclude(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) options = ObjectLike({ "source": None, "dest": "_site", "fork": True, "appcache": False, "debug": False, "pygments": False }) config = SiteConfig(options) from fs import filters, listdir base_filters = [ config.exclude_filter(), filters.no_hidden,filters.no_system] r = listdir(site.SITE_DIR,recursed=True,filters=base_filters) print >>sys.stderr, r assert r == ["abc_shim.js","index.md","unicode.md","js/init.js"]
def test_double_dashes(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) options, r = server_options_parser.parse_args(args=["--nofork"]) config = SiteConfig(options) header = { "Content-Type": "text/html", } content = """--- test: test --- abc---def 123---456 """ expected = """ abc---def 123---456 """ header2,content2 = config.split_matter_and_utf8_content(content,header) #print >>sys.stderr, "from:", content2, "to:", expected, "end" assert content2 == expected
def test_output(): apply_site_dirs("",force_project_path=join(pages_test_root,"web")) options = ObjectLike({ "source": None, "dest": "_site", "fork": True, "appcache": False, "debug": False, "pygments": False }) config = SiteConfig(options) assert config["output"] == join(pages_test_root,"web","_site") options = ObjectLike({ "source": None, "dest": "../output", "fork": True, "appcache": False, "debug": False, "pygments": False }) config = SiteConfig(options) assert config["output"] == join(pages_test_root,"output")
def test_broken_config(): apply_site_dirs("",force_project_path=join(pages_test_root,"broken-config")) config = SiteConfig({}) print >>sys.stderr, "config", config.config assert "config-error" in config assert config["config-error"] == "_config.yml is empty or malformed"
def test_missing_config(): apply_site_dirs("",force_project_path=join(pages_test_root,"broken-missing")) config = SiteConfig({}) assert "config-error" in config assert config["config-error"] == "_config.yml is missing"