diff tests/test_data_linker.py @ 411:e7b865f8f335

bake: Enable multiprocess baking. Baking is now done by running a worker per CPU, and sending jobs to them. This changes several things across the codebase: * Ability to not cache things related to pages other than the 'main' page (i.e. the page at the bottom of the execution stack). * Decouple the baking process from the bake records, so only the main process keeps track (and modifies) the bake record. * Remove the need for 'batch page getters' and loading a page directly from the page factories. There are various smaller changes too included here, including support for scope performance timers that are saved with the bake record and can be printed out to the console. Yes I got carried away. For testing, the in-memory 'mock' file-system doesn't work anymore, since we're spawning processes, so this is replaced by a 'tmpfs' file-system which is saved in temporary files on disk and deleted after tests have run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 12 Jun 2015 17:09:19 -0700
parents 27b10024f8d8
children f987b29d6fab
line wrap: on
line diff
--- a/tests/test_data_linker.py	Sat May 30 15:41:52 2015 -0700
+++ b/tests/test_data_linker.py	Fri Jun 12 17:09:19 2015 -0700
@@ -5,17 +5,17 @@
 
 
 @pytest.mark.parametrize(
-    'fs, page_path, expected',
+    'fs_fac, page_path, expected',
     [
-        (mock_fs().withPage('pages/foo'), 'foo.md',
+        (lambda: mock_fs().withPage('pages/foo'), 'foo.md',
             # is_dir, name, is_self, data
             [(False, 'foo', True, '/foo')]),
-        ((mock_fs()
+        ((lambda: mock_fs()
                 .withPage('pages/foo')
                 .withPage('pages/bar')),
             'foo.md',
             [(False, 'bar', False, '/bar'), (False, 'foo', True, '/foo')]),
-        ((mock_fs()
+        ((lambda: mock_fs()
                 .withPage('pages/baz')
                 .withPage('pages/something')
                 .withPage('pages/something/else')
@@ -26,7 +26,7 @@
                 (False, 'baz', False, '/baz'),
                 (False, 'foo', True, '/foo'),
                 (True, 'something', False, '/something')]),
-        ((mock_fs()
+        ((lambda: mock_fs()
                 .withPage('pages/something/else')
                 .withPage('pages/foo')
                 .withPage('pages/something/good')
@@ -35,7 +35,8 @@
             [(False, 'else', True, '/something/else'),
                 (False, 'good', False, '/something/good')])
     ])
-def test_linker_iteration(fs, page_path, expected):
+def test_linker_iteration(fs_fac, page_path, expected):
+    fs = fs_fac()
     with mock_fs_scope(fs):
         app = fs.getApp()
         app.config.set('site/pretty_urls', True)
@@ -54,16 +55,16 @@
 
 
 @pytest.mark.parametrize(
-        'fs, page_path, expected',
+        'fs_fac, page_path, expected',
         [
-            (mock_fs().withPage('pages/foo'), 'foo.md',
+            (lambda: mock_fs().withPage('pages/foo'), 'foo.md',
                 [('/foo', True)]),
-            ((mock_fs()
+            ((lambda: mock_fs()
                     .withPage('pages/foo')
                     .withPage('pages/bar')),
                 'foo.md',
                 [('/bar', False), ('/foo', True)]),
-            ((mock_fs()
+            ((lambda: mock_fs()
                     .withPage('pages/baz')
                     .withPage('pages/something/else')
                     .withPage('pages/foo')
@@ -71,7 +72,7 @@
                 'foo.md',
                 [('/bar', False), ('/baz', False),
                     ('/foo', True), ('/something/else', False)]),
-            ((mock_fs()
+            ((lambda: mock_fs()
                     .withPage('pages/something/else')
                     .withPage('pages/foo')
                     .withPage('pages/something/good')
@@ -80,7 +81,8 @@
                 [('/something/else', True),
                     ('/something/good', False)])
         ])
-def test_recursive_linker_iteration(fs, page_path, expected):
+def test_recursive_linker_iteration(fs_fac, page_path, expected):
+    fs = fs_fac()
     with mock_fs_scope(fs):
         app = fs.getApp()
         app.config.set('site/pretty_urls', True)