comparison tests/test_baking_baker.py @ 145:dce37d1d4f05

Fix unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 29 Nov 2014 20:55:41 -0800
parents 133845647083
children 61145dcd56e0
comparison
equal deleted inserted replaced
144:8d16ca75075f 145:dce37d1d4f05
48 48
49 49
50 def test_empty_bake(): 50 def test_empty_bake():
51 fs = mock_fs() 51 fs = mock_fs()
52 with mock_fs_scope(fs): 52 with mock_fs_scope(fs):
53 assert not os.path.isdir(fs.path('kitchen/_counter')) 53 out_dir = fs.path('kitchen/_counter')
54 assert not os.path.isdir(out_dir)
54 app = fs.getApp() 55 app = fs.getApp()
55 baker = Baker(app) 56 baker = Baker(app, out_dir)
56 baker.bake() 57 baker.bake()
57 assert os.path.isdir(fs.path('kitchen/_counter')) 58 assert os.path.isdir(out_dir)
58 structure = fs.getStructure('kitchen/_counter') 59 structure = fs.getStructure('kitchen/_counter')
59 assert list(structure.keys()) == ['index.html'] 60 assert list(structure.keys()) == ['index.html']
60 61
61 62
62 def test_simple_bake(): 63 def test_simple_bake():
63 fs = (mock_fs() 64 fs = (mock_fs()
64 .withPage('posts/2010-01-01_post1.md', {'layout': 'none', 'format': 'none'}, 'post one') 65 .withPage('posts/2010-01-01_post1.md', {'layout': 'none', 'format': 'none'}, 'post one')
65 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something")) 66 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something"))
66 with mock_fs_scope(fs): 67 with mock_fs_scope(fs):
68 out_dir = fs.path('kitchen/_counter')
67 app = fs.getApp() 69 app = fs.getApp()
68 baker = Baker(app) 70 baker = Baker(app, out_dir)
69 baker.bake() 71 baker.bake()
70 structure = fs.getStructure('kitchen/_counter') 72 structure = fs.getStructure('kitchen/_counter')
71 assert structure == { 73 assert structure == {
72 '2010': {'01': {'01': {'post1.html': 'post one'}}}, 74 '2010': {'01': {'01': {'post1.html': 'post one'}}},
73 'index.html': 'something'} 75 'index.html': 'something'}
75 def test_removed(): 77 def test_removed():
76 fs = (mock_fs() 78 fs = (mock_fs()
77 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page') 79 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page')
78 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something")) 80 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something"))
79 with mock_fs_scope(fs): 81 with mock_fs_scope(fs):
82 out_dir = fs.path('kitchen/_counter')
80 app = fs.getApp() 83 app = fs.getApp()
81 baker = Baker(app) 84 baker = Baker(app, out_dir)
82 baker.bake() 85 baker.bake()
83 structure = fs.getStructure('kitchen/_counter') 86 structure = fs.getStructure('kitchen/_counter')
84 assert structure == { 87 assert structure == {
85 'foo.html': 'a foo page', 88 'foo.html': 'a foo page',
86 'index.html': 'something'} 89 'index.html': 'something'}
87 90
88 os.remove(fs.path('kitchen/pages/foo.md')) 91 os.remove(fs.path('kitchen/pages/foo.md'))
89 app = fs.getApp() 92 app = fs.getApp()
90 baker = Baker(app) 93 baker = Baker(app, out_dir)
91 baker.bake() 94 baker.bake()
92 structure = fs.getStructure('kitchen/_counter') 95 structure = fs.getStructure('kitchen/_counter')
93 assert structure == { 96 assert structure == {
94 'index.html': 'something'} 97 'index.html': 'something'}
95 98
96 def test_record_version_change(): 99 def test_record_version_change():
97 fs = (mock_fs() 100 fs = (mock_fs()
98 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page')) 101 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page'))
99 with mock_fs_scope(fs): 102 with mock_fs_scope(fs):
103 out_dir = fs.path('kitchen/_counter')
100 app = fs.getApp() 104 app = fs.getApp()
101 baker = Baker(app) 105 baker = Baker(app, out_dir)
102 baker.bake() 106 baker.bake()
103 mtime = os.path.getmtime(fs.path('kitchen/_counter/foo.html')) 107 mtime = os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
104 108
105 app = fs.getApp() 109 app = fs.getApp()
106 baker = Baker(app) 110 baker = Baker(app, out_dir)
107 baker.bake() 111 baker.bake()
108 assert mtime == os.path.getmtime(fs.path('kitchen/_counter/foo.html')) 112 assert mtime == os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
109 113
110 BakeRecord.RECORD_VERSION += 1 114 BakeRecord.RECORD_VERSION += 1
111 try: 115 try:
112 app = fs.getApp() 116 app = fs.getApp()
113 baker = Baker(app) 117 baker = Baker(app, out_dir)
114 baker.bake() 118 baker.bake()
115 assert mtime < os.path.getmtime(fs.path('kitchen/_counter/foo.html')) 119 assert mtime < os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
116 finally: 120 finally:
117 BakeRecord.RECORD_VERSION -= 1 121 BakeRecord.RECORD_VERSION -= 1
118 122