Mercurial > piecrust2
comparison tests/test_data_assetor.py @ 6:f5ca5c5bed85
More Python 3 fixes, modularization, and new unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 16 Aug 2014 08:15:30 -0700 |
parents | |
children | 43091c9837bf |
comparison
equal
deleted
inserted
replaced
5:474c9882decf | 6:f5ca5c5bed85 |
---|---|
1 import pytest | |
2 from mock import MagicMock | |
3 from piecrust.data.assetor import Assetor, UnsupportedAssetsError | |
4 from .mockutil import mock_fs, mock_fs_scope | |
5 | |
6 | |
7 @pytest.mark.parametrize('fs, expected', [ | |
8 (mock_fs().withPage('foo/bar'), {}), | |
9 (mock_fs() | |
10 .withPage('foo/bar') | |
11 .withPageAsset('foo/bar', 'one.txt', 'one'), | |
12 {'one': 'one'}), | |
13 (mock_fs() | |
14 .withPage('foo/bar') | |
15 .withPageAsset('foo/bar', 'one.txt', 'one') | |
16 .withPageAsset('foo/bar', 'two.txt', 'two'), | |
17 {'one': 'one', 'two': 'two'}) | |
18 ]) | |
19 def test_assets(fs, expected): | |
20 with mock_fs_scope(fs): | |
21 page = MagicMock() | |
22 page.app = fs.getApp() | |
23 page.path = fs.path('/kitchen/_content/pages/foo/bar.md') | |
24 assetor = Assetor(page, '/foo/bar') | |
25 for en in expected.keys(): | |
26 assert hasattr(assetor, en) | |
27 path = '/foo/bar/%s.txt' % en | |
28 assert getattr(assetor, en) == path | |
29 assert assetor[en] == path | |
30 | |
31 | |
32 def test_missing_asset(): | |
33 with pytest.raises(KeyError): | |
34 fs = mock_fs().withPage('foo/bar') | |
35 with mock_fs_scope(fs): | |
36 page = MagicMock() | |
37 page.app = fs.getApp() | |
38 page.path = fs.path('/kitchen/_content/pages/foo/bar.md') | |
39 assetor = Assetor(page, '/foo/bar') | |
40 assetor['this_doesnt_exist'] | |
41 | |
42 | |
43 def test_multiple_assets_with_same_name(): | |
44 with pytest.raises(UnsupportedAssetsError): | |
45 fs = (mock_fs() | |
46 .withPage('foo/bar') | |
47 .withPageAsset('foo/bar', 'one.txt', 'one text') | |
48 .withPageAsset('foo/bar', 'one.jpg', 'one picture')) | |
49 with mock_fs_scope(fs): | |
50 page = MagicMock() | |
51 page.app = fs.getApp() | |
52 page.path = fs.path('/kitchen/_content/pages/foo/bar.md') | |
53 assetor = Assetor(page, '/foo/bar') | |
54 assetor['one'] | |
55 |