<s> """<STR_LIT>""" <EOL> from hyde . generator import Generator <EOL> from hyde . site import Site <EOL> from fswrap import File , Folder <EOL> from pyquery import PyQuery <EOL> import yaml <EOL> TEST_SITE = File ( __file__ ) . parent . parent . child_folder ( '<STR_LIT>' ) <EOL> class TestMeta ( object ) : <EOL> def setUp ( self ) : <EOL> TEST_SITE . make ( ) <EOL> TEST_SITE . parent . child_folder ( <EOL> '<STR_LIT>' ) . copy_contents_to ( TEST_SITE ) <EOL> def tearDown ( self ) : <EOL> TEST_SITE . delete ( ) <EOL> def test_can_set_standard_attributes ( self ) : <EOL> text = """<STR_LIT>""" <EOL> about2 = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> about2 . write ( text ) <EOL> s = Site ( TEST_SITE ) <EOL> s . load ( ) <EOL> res = s . content . resource_from_path ( about2 . path ) <EOL> assert res . is_processable <EOL> s . config . plugins = [ '<STR_LIT>' ] <EOL> gen = Generator ( s ) <EOL> gen . generate_all ( ) <EOL> assert not res . meta . is_processable <EOL> assert not res . is_processable <EOL> def test_ignores_pattern_in_content ( self ) : <EOL> text = """<STR_LIT>""" <EOL> about2 = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> about2 . write ( text ) <EOL> s = Site ( TEST_SITE ) <EOL> s . load ( ) <EOL> res = s . content . resource_from_path ( about2 . path ) <EOL> assert res . is_processable <EOL> s . config . plugins = [ '<STR_LIT>' ] <EOL> gen = Generator ( s ) <EOL> gen . generate_all ( ) <EOL> target = File ( Folder ( s . config . deploy_root_path ) . child ( '<STR_LIT>' ) ) <EOL> text = target . read_all ( ) <EOL> q = PyQuery ( text ) <EOL> assert q ( "<STR_LIT>" ) . length == <NUM_LIT:2> <EOL> assert q ( "<STR_LIT>" ) . text ( ) . strip ( ) == "<STR_LIT>" <EOL> assert q ( "<STR_LIT>" ) . text ( ) . strip ( ) == "<STR_LIT>" <EOL> def test_can_load_front_matter ( self ) : <EOL> d = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> text = """<STR_LIT>""" <EOL> about2 = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> about2 . write ( text % d ) <EOL> s = Site ( TEST_SITE ) <EOL> s . config . plugins = [ '<STR_LIT>' ] <EOL> gen = Generator ( s ) <EOL> gen . generate_all ( ) <EOL> res = s . content . resource_from_path ( about2 . path ) <EOL> assert hasattr ( res , '<STR_LIT>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT:title>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT>' ) <EOL> assert res . meta . title == "<STR_LIT>" <EOL> assert res . meta . author == "<STR_LIT>" <EOL> assert res . meta . twitter == "<STR_LIT>" <EOL> target = File ( Folder ( s . config . deploy_root_path ) . child ( '<STR_LIT>' ) ) <EOL> text = target . read_all ( ) <EOL> q = PyQuery ( text ) <EOL> for k , v in d . items ( ) : <EOL> assert v in q ( "<STR_LIT>" + k ) . text ( ) <EOL> def test_can_load_from_node_meta ( self ) : <EOL> d = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> text = """<STR_LIT>""" <EOL> about2 = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> about2 . write ( text % d ) <EOL> meta = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> meta . write ( yaml . dump ( d ) ) <EOL> s = Site ( TEST_SITE ) <EOL> s . config . plugins = [ '<STR_LIT>' ] <EOL> gen = Generator ( s ) <EOL> gen . generate_all ( ) <EOL> res = s . content . resource_from_path ( about2 . path ) <EOL> assert hasattr ( res , '<STR_LIT>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT:title>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT>' ) <EOL> assert res . meta . title == "<STR_LIT>" <EOL> assert res . meta . author == "<STR_LIT>" <EOL> assert res . meta . twitter == "<STR_LIT>" <EOL> target = File ( Folder ( s . config . deploy_root_path ) . child ( '<STR_LIT>' ) ) <EOL> text = target . read_all ( ) <EOL> q = PyQuery ( text ) <EOL> for k , v in d . items ( ) : <EOL> if not k == '<STR_LIT:title>' : <EOL> assert v in q ( "<STR_LIT>" + k ) . text ( ) <EOL> assert q ( "<STR_LIT>" ) . text ( ) == "<STR_LIT>" <EOL> def test_can_load_from_site_meta ( self ) : <EOL> d = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> text = """<STR_LIT>""" <EOL> about2 = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> about2 . write ( text % d ) <EOL> meta = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> meta . write ( yaml . dump ( d ) ) <EOL> s = Site ( TEST_SITE ) <EOL> s . config . plugins = [ '<STR_LIT>' ] <EOL> s . config . meta = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> gen = Generator ( s ) <EOL> gen . generate_all ( ) <EOL> res = s . content . resource_from_path ( about2 . path ) <EOL> assert hasattr ( res , '<STR_LIT>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT:title>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT>' ) <EOL> assert hasattr ( res . meta , '<STR_LIT>' ) <EOL> assert res . meta . title == "<STR_LIT>" <EOL> assert res . meta . author == "<STR_LIT>" <EOL> assert res . meta . twitter == "<STR_LIT>" <EOL> target = File ( Folder ( s . config . deploy_root_path ) . child ( '<STR_LIT>' ) ) <EOL> text = target . read_all ( ) <EOL> q = PyQuery ( text ) <EOL> for k , v in d . items ( ) : <EOL> if not k == '<STR_LIT:title>' : <EOL> assert v in q ( "<STR_LIT>" + k ) . text ( ) <EOL> assert q ( "<STR_LIT>" ) . text ( ) == "<STR_LIT>" <EOL> def test_multiple_levels ( self ) : <EOL> page_d = { '<STR_LIT:title>' : '<STR_LIT>' } <EOL> blog_d = { '<STR_LIT>' : '<STR_LIT>' } <EOL> content_d = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> site_d = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> text = """<STR_LIT>""" <EOL> about2 = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> about2 . write ( text % page_d ) <EOL> content_meta = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> content_meta . write ( yaml . dump ( content_d ) ) <EOL> content_meta = File ( TEST_SITE . child ( '<STR_LIT>' ) ) <EOL> content_meta . write ( yaml . dump ( blog_d ) ) <EOL> s = Site ( TEST_SITE ) <EOL> s . config . plugins = [ '<STR_LIT>' ] <EOL> s . config . meta = site_d <EOL> gen = Generator ( s ) <EOL> gen . generate_all ( ) <EOL> expected = { } <EOL> expected . update ( site_d ) <EOL> expected . update ( content_d ) <EOL> expected . update ( blog_d ) <EOL> expected . update ( page_d ) <EOL> res = s . content . resource_from_path ( about2 . path ) <EOL> assert hasattr ( res , '<STR_LIT>' ) <EOL> for k , v in expected . items ( ) : <EOL> assert hasattr ( res . meta , k ) <EOL> assert getattr ( res . meta , k ) == v <EOL> target = File ( <EOL> Folder ( s . config . deploy_root_path ) . child ( '<STR_LIT>' ) ) <EOL> text = target . read_all ( ) <EOL> q = PyQuery ( text ) <EOL> for k , v in expected . items ( ) : <EOL> if k != '<STR_LIT>' : <EOL> assert v in q ( "<STR_LIT>" + k ) . text ( ) </s>
