diff tests/test_sources_base.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 dd25bd3ce1f9
children f987b29d6fab
line wrap: on
line diff
--- a/tests/test_sources_base.py	Sat May 30 15:41:52 2015 -0700
+++ b/tests/test_sources_base.py	Fri Jun 12 17:09:19 2015 -0700
@@ -6,22 +6,23 @@
 from .pathutil import slashfix
 
 
-@pytest.mark.parametrize('fs, expected_paths, expected_slugs', [
-        (mock_fs(), [], []),
-        (mock_fs().withPage('test/foo.html'),
+@pytest.mark.parametrize('fs_fac, expected_paths, expected_slugs', [
+        (lambda: mock_fs(), [], []),
+        (lambda: mock_fs().withPage('test/foo.html'),
             ['foo.html'], ['foo']),
-        (mock_fs().withPage('test/foo.md'),
+        (lambda: mock_fs().withPage('test/foo.md'),
             ['foo.md'], ['foo']),
-        (mock_fs().withPage('test/foo.ext'),
+        (lambda: mock_fs().withPage('test/foo.ext'),
             ['foo.ext'], ['foo.ext']),
-        (mock_fs().withPage('test/foo/bar.html'),
+        (lambda: mock_fs().withPage('test/foo/bar.html'),
             ['foo/bar.html'], ['foo/bar']),
-        (mock_fs().withPage('test/foo/bar.md'),
+        (lambda: mock_fs().withPage('test/foo/bar.md'),
             ['foo/bar.md'], ['foo/bar']),
-        (mock_fs().withPage('test/foo/bar.ext'),
+        (lambda: mock_fs().withPage('test/foo/bar.ext'),
             ['foo/bar.ext'], ['foo/bar.ext']),
         ])
-def test_default_source_factories(fs, expected_paths, expected_slugs):
+def test_default_source_factories(fs_fac, expected_paths, expected_slugs):
+    fs = fs_fac()
     fs.withConfig({
         'site': {
             'sources': {
@@ -131,7 +132,7 @@
         app = fs.getApp()
         r = PageRef(app, 'whatever:doesnt_exist.md')
         with pytest.raises(Exception):
-            r.possible_rel_paths
+            r.possible_ref_specs
 
 
 def test_page_ref_with_missing_file():
@@ -139,9 +140,11 @@
     with mock_fs_scope(fs):
         app = fs.getApp()
         r = PageRef(app, 'pages:doesnt_exist.%ext%')
-        assert r.possible_rel_paths == [
-                'doesnt_exist.html', 'doesnt_exist.md', 'doesnt_exist.textile']
-        assert r.source_name == 'pages'
+        assert r.possible_ref_specs == [
+                'pages:doesnt_exist.html', 'pages:doesnt_exist.md',
+                'pages:doesnt_exist.textile']
+        with pytest.raises(PageNotFoundError):
+            r.source_name
         with pytest.raises(PageNotFoundError):
             r.rel_path
         with pytest.raises(PageNotFoundError):