annotate tests/test_pipelines_asset.py @ 1051:971b4d67e82a

serve: Fix problems with assets disappearing between servings. When an asset file changes, its source's pipeline is re-run. But that created a bake record that only had that pipeline's output, so the other outputs were incorrectly considered empty and therefore any stray files were removed. Now we copy over bake records for the pipelines we don't run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 26 Jan 2018 18:05:02 -0800
parents 45ad976712ec
children 2b2eaee96121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import time
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
3 import random
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import inspect
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 import pytest
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 from piecrust.pipelines.asset import get_filtered_processors
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 from piecrust.pipelines.records import MultiRecord
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 from piecrust.processing.base import SimpleFileProcessor
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 from .mockutil import mock_fs, mock_fs_scope
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 class FooProcessor(SimpleFileProcessor):
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
13 def __init__(self, name=None, exts=None, open_func=None):
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
14 self.PROCESSOR_NAME = name or 'foo'
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
15 exts = exts or {'foo': 'foo'}
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
16 super().__init__(exts)
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 self.open_func = open_func or open
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 def _doProcess(self, in_path, out_path):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 with self.open_func(in_path, 'r') as f:
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 text = f.read()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 with self.open_func(out_path, 'w') as f:
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 f.write("%s: %s" % (self.PROCESSOR_NAME.upper(), text))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 return True
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
27 def _get_test_plugin_name():
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
28 return 'foo_%d' % random.randrange(1000)
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
31 def _get_test_fs(*, plugins=None, processors=None):
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
32 plugins = plugins or []
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
33 processors = processors or []
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
34 processors.append('copy')
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 return (mock_fs()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 .withDir('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 .withConfig({
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
38 'site': {
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
39 'plugins': plugins
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
40 },
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 'pipelines': {
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 'asset': {
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 'processors': processors
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 }
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 }
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 }))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
49 def _create_test_plugin(fs, plugname, *, foo_name=None, foo_exts=None):
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 src = [
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 'from piecrust.plugins.base import PieCrustPlugin',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 'from piecrust.processing.base import SimpleFileProcessor']
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 foo_lines = inspect.getsourcelines(FooProcessor)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 src += ['']
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 src += map(lambda l: l.rstrip('\n'), foo_lines[0])
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 src += [
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 '',
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
60 'class FooPlugin(PieCrustPlugin):',
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 ' def getProcessors(self):',
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
62 ' yield FooProcessor(%s, %s)' % (repr(foo_name),
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
63 repr(foo_exts)),
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 '',
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
65 '__piecrust_plugin__ = FooPlugin']
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
67 print("Creating plugin with source:\n%s" % '\n'.join(src))
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
68 fs.withFile('kitchen/plugins/%s.py' % plugname, '\n'.join(src))
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 def _bake_assets(fs):
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
72 fs.runChef('bake', '-p', 'asset', '-o', fs.path('counter'))
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 def test_empty():
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 fs = _get_test_fs()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 expected = {}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 expected = {}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 def test_one_file():
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 fs = (_get_test_fs()
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
87 .withFile('kitchen/assets/something.foo', 'A test file.'))
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 expected = {}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 _bake_assets(fs)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
92 expected = {'something.foo': 'A test file.'}
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 def test_one_level_dirtyness():
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 fs = (_get_test_fs()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 .withFile('kitchen/assets/blah.foo', 'A test file.'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 expected = {'blah.foo': 'A test file.'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 mtime = os.path.getmtime(fs.path('/counter/blah.foo'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 assert abs(time.time() - mtime) <= 2
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 time.sleep(1)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 assert mtime == os.path.getmtime(fs.path('/counter/blah.foo'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 time.sleep(1)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 fs.withFile('kitchen/assets/blah.foo', 'A new test file.')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 expected = {'blah.foo': 'A new test file.'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 assert mtime < os.path.getmtime(fs.path('/counter/blah.foo'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 def test_two_levels_dirtyness():
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
120 plugname = _get_test_plugin_name()
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
121 fs = (_get_test_fs(plugins=[plugname], processors=['foo'])
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 .withFile('kitchen/assets/blah.foo', 'A test file.'))
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
123 _create_test_plugin(fs, plugname, foo_exts={'foo': 'bar'})
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 expected = {'blah.bar': 'FOO: A test file.'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 mtime = os.path.getmtime(fs.path('/counter/blah.bar'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 assert abs(time.time() - mtime) <= 2
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 time.sleep(1)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 assert mtime == os.path.getmtime(fs.path('/counter/blah.bar'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 time.sleep(1)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 fs.withFile('kitchen/assets/blah.foo', 'A new test file.')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 expected = {'blah.bar': 'FOO: A new test file.'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 assert mtime < os.path.getmtime(fs.path('/counter/blah.bar'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 def test_removed():
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 fs = (_get_test_fs()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 .withFile('kitchen/assets/blah1.foo', 'A test file.')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 .withFile('kitchen/assets/blah2.foo', 'Ooops'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 expected = {
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 'blah1.foo': 'A test file.',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 'blah2.foo': 'Ooops'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 assert expected == fs.getStructure('kitchen/assets')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 time.sleep(1)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 os.remove(fs.path('/kitchen/assets/blah2.foo'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158 expected = {
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 'blah1.foo': 'A test file.'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 assert expected == fs.getStructure('kitchen/assets')
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
161 _bake_assets(fs)
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 def test_record_version_change():
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
166 plugname = _get_test_plugin_name()
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
167 fs = (_get_test_fs(plugins=[plugname], processors=['foo'])
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 .withFile('kitchen/assets/blah.foo', 'A test file.'))
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
169 _create_test_plugin(fs, plugname)
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 with mock_fs_scope(fs):
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
171 time.sleep(1)
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 _bake_assets(fs)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
173 time.sleep(0.1)
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
174 mtime = os.path.getmtime(fs.path('counter/blah.foo'))
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 time.sleep(1)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 _bake_assets(fs)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
178 time.sleep(0.1)
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
179 assert mtime == os.path.getmtime(fs.path('counter/blah.foo'))
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 MultiRecord.RECORD_VERSION += 1
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 try:
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
183 time.sleep(1)
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 _bake_assets(fs)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
185 time.sleep(0.1)
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
186 assert mtime < os.path.getmtime(fs.path('counter/blah.foo'))
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 finally:
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 MultiRecord.RECORD_VERSION -= 1
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
191 @pytest.mark.parametrize('patterns, expected', [
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
192 (['_'],
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193 {'something.html': 'A test file.'}),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194 (['html'],
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 {}),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 (['/^_/'],
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 {'something.html': 'A test file.',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 'foo': {'_important.html': 'Important!'}})
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 ])
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200 def test_ignore_pattern(patterns, expected):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 fs = (_get_test_fs()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 .withFile('kitchen/assets/something.html', 'A test file.')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 .withFile('kitchen/assets/_hidden.html', 'Shhh')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204 .withFile('kitchen/assets/foo/_important.html', 'Important!'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 fs.withConfig({'pipelines': {'asset': {'ignore': patterns}}})
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 assert {} == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 _bake_assets(fs)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 assert expected == fs.getStructure('counter')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 @pytest.mark.parametrize('names, expected', [
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 ('all', ['cleancss', 'compass', 'copy', 'concat', 'less', 'requirejs',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 'sass', 'sitemap', 'uglifyjs', 'pygments_style']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 ('all -sitemap', ['cleancss', 'copy', 'compass', 'concat', 'less',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 'requirejs', 'sass', 'uglifyjs', 'pygments_style']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 ('-sitemap -less -sass all', ['cleancss', 'copy', 'compass', 'concat',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218 'requirejs', 'uglifyjs',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 'pygments_style']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220 ('copy', ['copy']),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 ('less sass', ['less', 'sass'])
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 ])
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223 def test_filter_processor(names, expected):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 fs = mock_fs().withConfig()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225 with mock_fs_scope(fs):
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 app = fs.getApp()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227 processors = app.plugin_loader.getProcessors()
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 procs = get_filtered_processors(processors, names)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229 actual = [p.PROCESSOR_NAME for p in procs]
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230 assert sorted(actual) == sorted(expected)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231