annotate tests/conftest.py @ 1188:a7c43131d871

bake: Fix file write flushing problem with Python 3.8+ Writing the cache files fails in Python 3.8 because it looks like flushing behaviour has changed. We need to explicitly flush. And even then, in very rare occurrences, it looks like it can still run into racing conditions, so we do a very hacky and ugly "retry" loop when fetching cached data :(
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 15 Jun 2021 22:36:23 -0700
parents 161cba5d031a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
1 import io
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
2 import re
86
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import sys
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
4 import time
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
5 import pprint
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
6 import os.path
86
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 import logging
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
8 import pytest
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
9 import yaml
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
10 import colorama
520
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
11 from werkzeug.exceptions import HTTPException
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
12 from piecrust.app import PieCrustFactory, apply_variants_and_values
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
13 from piecrust.configuration import merge_dicts
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
14 from .mockutil import mock_fs, mock_fs_scope
86
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 def pytest_runtest_setup(item):
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 pass
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 def pytest_addoption(parser):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
22 parser.addoption(
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
23 '--pc-log-debug',
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
24 action='store_true',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
25 help="Sets the PieCrust logger to output debug info to stdout.")
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
26 parser.addoption(
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
27 '--pc-log-file',
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
28 help="Sets the PieCrust logger to write to a file.")
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
29 parser.addoption(
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
30 '--pc-mock-debug',
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
31 action='store_true',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
32 help="Prints contents of the mock file-system.")
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
33 parser.addoption(
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
34 '--pc-leave-mockfs',
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
35 action='store_true',
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
36 help="Leave the contents of the mock file-system on disk.")
86
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 def pytest_configure(config):
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
40 if config.getoption('--pc-log-debug'):
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
41 root_logger = logging.getLogger()
86
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 hdl = logging.StreamHandler(stream=sys.stdout)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
43 root_logger.addHandler(hdl)
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
44 root_logger.setLevel(logging.DEBUG)
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
45
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
46 from .basefs import TestFileSystemBase
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
47 TestFileSystemBase._use_chef_debug = True
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
48 TestFileSystemBase._pytest_log_handler = hdl
86
1cd67680c38c Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
50 log_file = config.getoption('--pc-log-file')
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
51 if log_file:
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
52 hdl = logging.StreamHandler(
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
53 stream=open(log_file, 'w', encoding='utf8'))
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
54 logging.getLogger().addHandler(hdl)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
55
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
56 if config.getoption('--pc-leave-mockfs'):
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
57 from .basefs import TestFileSystemBase
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
58 TestFileSystemBase._leave_mockfs = True
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
59
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
60
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
61 def pytest_collect_file(parent, path):
397
879b6b5647a8 tests: Move all bakes/cli/servings tests files to have a YAML extension.
Ludovic Chabant <ludovic@chabant.com>
parents: 391
diff changeset
62 if path.ext == '.yaml' and path.basename.startswith("test"):
879b6b5647a8 tests: Move all bakes/cli/servings tests files to have a YAML extension.
Ludovic Chabant <ludovic@chabant.com>
parents: 391
diff changeset
63 category = os.path.basename(path.dirname)
879b6b5647a8 tests: Move all bakes/cli/servings tests files to have a YAML extension.
Ludovic Chabant <ludovic@chabant.com>
parents: 391
diff changeset
64 if category == 'bakes':
1187
161cba5d031a tests: pytest deprecated API
Ludovic Chabant <ludovic@chabant.com>
parents: 1169
diff changeset
65 return BakeTestFile.from_parent(parent, fspath=path)
397
879b6b5647a8 tests: Move all bakes/cli/servings tests files to have a YAML extension.
Ludovic Chabant <ludovic@chabant.com>
parents: 391
diff changeset
66 elif category == 'cli':
1187
161cba5d031a tests: pytest deprecated API
Ludovic Chabant <ludovic@chabant.com>
parents: 1169
diff changeset
67 return ChefTestFile.from_parent(parent, fspath=path)
397
879b6b5647a8 tests: Move all bakes/cli/servings tests files to have a YAML extension.
Ludovic Chabant <ludovic@chabant.com>
parents: 391
diff changeset
68 elif category == 'servings':
1187
161cba5d031a tests: pytest deprecated API
Ludovic Chabant <ludovic@chabant.com>
parents: 1169
diff changeset
69 return ServeTestFile.from_parent(parent, fspath=path)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
70
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
71
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
72 def repr_nested_failure(excinfo):
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
73 # PyTest sadly doesn't show nested exceptions so we have to do it
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
74 # ourselves... it's not pretty, but at least it's more useful.
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
75 if excinfo.value.__cause__:
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
76 import traceback
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
77 ex = excinfo.value
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
78 return '\n'.join(
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
79 traceback.format_exception(
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
80 type(ex), ex, ex.__traceback__))
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
81 return ''
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
82
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
83
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
84 class YamlTestFileBase(pytest.File):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
85 def collect(self):
1160
cf6b2bf042fb tests: Fix YAML warning in tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1142
diff changeset
86 spec = yaml.load_all(self.fspath.open(encoding='utf8'),
cf6b2bf042fb tests: Fix YAML warning in tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1142
diff changeset
87 Loader=yaml.SafeLoader)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
88 for i, item in enumerate(spec):
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
89 name = '%s_%d' % (self.fspath.basename, i)
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
90 if 'test_name' in item:
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
91 name += '_%s' % item['test_name']
1187
161cba5d031a tests: pytest deprecated API
Ludovic Chabant <ludovic@chabant.com>
parents: 1169
diff changeset
92 yield self.__item_class__.from_parent(self, name=name, spec=item)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
93
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
94
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
95 class YamlTestItemBase(pytest.Item):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
96 def __init__(self, name, parent, spec):
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
97 super(YamlTestItemBase, self).__init__(name, parent)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
98 self.spec = spec
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
99
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
100 @property
674
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
101 def is_theme_site(self):
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
102 return self.spec.get('theme_config') is not None
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
103
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
104 @property
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
105 def mock_debug(self):
1028
63f118c773ee tests: Prevent conflicts in later `pytest` versions.
Ludovic Chabant <ludovic@chabant.com>
parents: 979
diff changeset
106 return bool(self.config.getoption('--pc-mock-debug'))
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
107
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
108 def _prepareMockFs(self):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
109 fs = mock_fs()
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
110
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
111 if self.spec.get('no_kitchen', False):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
112 fs.withDir('/')
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
113 return fs
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
114
674
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
115 # Suppress any formatting or layout so we can compare
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
116 # much simpler strings.
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
117 config = {
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
118 'site': {
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
119 'default_format': 'none',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
120 'default_page_layout': 'none',
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
121 'default_post_layout': 'none'}
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
122 }
674
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
123
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
124 # Website or theme config.
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
125 test_theme_config = self.spec.get('theme_config')
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
126 if test_theme_config is not None:
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
127 merge_dicts(config, test_theme_config)
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
128 fs.withThemeConfig(config)
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
129 else:
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
130 test_config = self.spec.get('config')
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
131 if test_config is not None:
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
132 merge_dicts(config, test_config)
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
133 fs.withConfig(config)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
134
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
135 # Input file-system.
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
136 input_files = self.spec.get('in')
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
137 if input_files is not None:
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
138 _add_mock_files(fs, '/kitchen', input_files)
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
139
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
140 if self.mock_debug:
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
141 res = '\nMock File-System:\n'
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
142 res += 'At: %s\n' % fs.path('')
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
143 res += '\n'.join(print_fs_tree(fs.path('')))
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
144 res += '\n'
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
145 print(res)
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
146
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
147 return fs
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
148
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
149 def repr_failure(self, excinfo):
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
150 res = super(YamlTestItemBase, self).repr_failure(excinfo)
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
151 nested_res = repr_nested_failure(excinfo)
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
152 if nested_res:
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
153 res = str(res) + '\n' + nested_res
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
154 return res
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
155
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
156
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
157 def check_expected_outputs(spec, fs, error_type):
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
158 cctx = CompareContext()
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
159 expected_output_files = spec.get('out')
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
160 if expected_output_files:
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
161 actual = fs.getStructure('kitchen/_counter')
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
162 error = _compare_dicts(expected_output_files, actual, cctx)
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
163 if error:
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
164 raise error_type(error)
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
165
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
166 pyversion = sys.hexversion
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
167
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
168 expected_partial_files = spec.get('outfiles')
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
169 if expected_partial_files:
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
170 keys = list(sorted(expected_partial_files.keys()))
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
171 for key in keys:
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
172
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
173 cleankey, valid = _eval_pyversion_condition(key)
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
174 if not valid:
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
175 logging.getLogger().warning(
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
176 "Skipping '%s' because the python version condition "
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
177 "was not met" % key)
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
178 continue
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
179
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
180 try:
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
181 actual = fs.getFileEntry('kitchen/_counter/' +
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
182 cleankey.lstrip('/'))
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
183 except Exception as e:
559
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
184 lines = print_fs_tree(fs.path('kitchen/_counter'))
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
185 raise error_type([
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
186 "Can't access output file %s: %s" % (cleankey, e),
559
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
187 "Got output directory:"] +
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
188 lines)
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
189
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
190 expected = expected_partial_files[key]
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
191 # HACK because for some reason PyYAML adds a new line for
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
192 # those and I have no idea why.
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
193 actual = actual.rstrip('\n')
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
194 expected = expected.rstrip('\n')
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
195 cctx.path = cleankey
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
196 cmpres = _compare_str(expected, actual, cctx)
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
197 if cmpres:
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
198 raise error_type(cmpres)
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
199
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
200
559
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
201 def print_fs_tree(rootpath):
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
202 import os
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
203 import os.path
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
204 lines = []
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
205 offset = len(rootpath)
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
206 for pathname, dirnames, filenames in os.walk(rootpath):
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
207 level = pathname[offset:].count(os.sep)
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
208 indent = ' ' * 4 * (level)
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
209 lines.append(indent + os.path.basename(pathname) + '/')
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
210 indent2 = ' ' * 4 * (level + 1)
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
211 for f in filenames:
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
212 lines.append(indent2 + f)
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
213 return lines
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
214
b95977d97652 tests: Print more information when a bake test fails to find an output file.
Ludovic Chabant <ludovic@chabant.com>
parents: 553
diff changeset
215
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
216 class ChefTestItem(YamlTestItemBase):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
217 __initialized_logging__ = False
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
218
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
219 def runtest(self):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
220 if not ChefTestItem.__initialized_logging__:
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
221 colorama.init()
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
222 hdl = logging.StreamHandler(stream=sys.stdout)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
223 logging.getLogger().addHandler(hdl)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
224 logging.getLogger().setLevel(logging.INFO)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
225 ChefTestItem.__initialized_logging__ = True
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
226
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
227 fs = self._prepareMockFs()
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
228
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
229 argv = self.spec['args']
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
230 if isinstance(argv, str):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
231 argv = argv.split(' ')
674
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
232 if self.is_theme_site:
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
233 argv.insert(0, '--theme')
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
234 if not self.spec.get('no_kitchen', False):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
235 argv = ['--root', fs.path('/kitchen')] + argv
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
236
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
237 with mock_fs_scope(fs, keep=self.mock_debug):
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
238 cwd = os.getcwd()
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
239 memstream = io.StringIO()
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
240 hdl = logging.StreamHandler(stream=memstream)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
241 logging.getLogger().addHandler(hdl)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
242 try:
583
1eda551ee681 cli: More proper argument parsing for the main/root arguments.
Ludovic Chabant <ludovic@chabant.com>
parents: 582
diff changeset
243 from piecrust.main import _pre_parse_chef_args, _run_chef
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
244 os.chdir(fs.path('/'))
674
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
245 pre_args = _pre_parse_chef_args(argv)
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
246 exit_code = _run_chef(pre_args, argv)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
247 finally:
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
248 logging.getLogger().removeHandler(hdl)
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
249 os.chdir(cwd)
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
250
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
251 expected_code = self.spec.get('code', 0)
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
252 if expected_code != exit_code:
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
253 raise UnexpectedChefExitCodeError("Got '%d', expected '%d'." %
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
254 (exit_code, expected_code))
493
95b77239c3b7 tests: Fix `find` tests on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 466
diff changeset
255
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
256 expected_out = self.spec.get('out', None)
567
a65f04ddbea2 showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents: 559
diff changeset
257 if expected_out is not None:
a65f04ddbea2 showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents: 559
diff changeset
258 actual_out = memstream.getvalue()
779
982de61e7da9 tests: Fix some CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 778
diff changeset
259 if not self.spec.get('no_strip'):
982de61e7da9 tests: Fix some CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 778
diff changeset
260 actual_out = actual_out.rstrip(' \n')
982de61e7da9 tests: Fix some CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 778
diff changeset
261 expected_out = expected_out.rstrip(' \n')
567
a65f04ddbea2 showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents: 559
diff changeset
262 if self.spec.get('replace_out_path_sep'):
a65f04ddbea2 showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents: 559
diff changeset
263 expected_out = expected_out.replace('/', os.sep)
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
264 if expected_out != actual_out:
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
265 raise UnexpectedChefOutputError(expected_out, actual_out)
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
266
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
267 expected_files = self.spec.get('files', None)
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
268 if expected_files is not None:
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
269 for path in expected_files:
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
270 path = '/' + path.lstrip('/')
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
271 if not os.path.exists(fs.path(path)):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
272 raise MissingChefOutputFileError(fs, path)
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
273
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
274 def reportinfo(self):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
275 return self.fspath, 0, "bake: %s" % self.name
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
276
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
277 def repr_failure(self, excinfo):
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
278 if isinstance(excinfo.value, UnexpectedChefExitCodeError):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
279 return str(excinfo.value)
1096
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
280 if isinstance(excinfo.value, UnexpectedChefOutputError):
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
281 return ('\n'.join(
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
282 ['Unexpected command output. Expected:',
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
283 excinfo.value.args[0],
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
284 "Got:",
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
285 excinfo.value.args[1]]))
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
286 if isinstance(excinfo.value, MissingChefOutputFileError):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
287 lines = print_fs_tree(excinfo.value.args[0].path(''))
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
288 return ('\n'.join(
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
289 ["Missing file: %s" % excinfo.value.args[1],
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
290 "Got output directory:"] +
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
291 lines))
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
292 return super(ChefTestItem, self).repr_failure(excinfo)
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
293
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
294
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
295 class UnexpectedChefExitCodeError(Exception):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
296 pass
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
297
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
298
1096
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
299 class UnexpectedChefOutputError(Exception):
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
300 pass
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
301
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
302
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
303 class MissingChefOutputFileError(Exception):
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
304 pass
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
305
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
306
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
307 class ChefTestFile(YamlTestFileBase):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
308 __item_class__ = ChefTestItem
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
309
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
310
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
311 class BakeTestItem(YamlTestItemBase):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
312 def runtest(self):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
313 fs = self._prepareMockFs()
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
314
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
315 from piecrust.baking.baker import Baker
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
316 with mock_fs_scope(fs, keep=self.mock_debug):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
317 out_dir = fs.path('kitchen/_counter')
674
f987b29d6fab tests: Add ability to run tests with a theme site.
Ludovic Chabant <ludovic@chabant.com>
parents: 673
diff changeset
318 app = fs.getApp(theme_site=self.is_theme_site)
466
456db44dcc53 bake: Pass the config variants and values from the CLI to the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 439
diff changeset
319
456db44dcc53 bake: Pass the config variants and values from the CLI to the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 439
diff changeset
320 values = self.spec.get('config_values')
456db44dcc53 bake: Pass the config variants and values from the CLI to the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 439
diff changeset
321 if values is not None:
456db44dcc53 bake: Pass the config variants and values from the CLI to the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 439
diff changeset
322 values = list(values.items())
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
323 variants = self.spec.get('config_variants')
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
324 apply_variants_and_values(app, variants, values)
466
456db44dcc53 bake: Pass the config variants and values from the CLI to the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 439
diff changeset
325
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
326 appfactory = PieCrustFactory(app.root_dir,
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
327 theme_site=self.is_theme_site,
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
328 config_variants=variants,
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
329 config_values=values)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
330 baker = Baker(appfactory, app, out_dir)
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
331 records = baker.bake()
398
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
332
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
333 if not records.success:
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 399
diff changeset
334 errors = []
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
335 for r in records.records:
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
336 for e in r.getEntries():
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
337 errors += e.getAllErrors()
411
e7b865f8f335 bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents: 399
diff changeset
338 raise BakeError(errors)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
339
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
340 check_expected_outputs(self.spec, fs, UnexpectedBakeOutputError)
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
341
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
342 def reportinfo(self):
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
343 return self.fspath, 0, "bake: %s" % self.name
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
344
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
345 def repr_failure(self, excinfo):
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
346 if isinstance(excinfo.value, UnexpectedBakeOutputError):
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
347 return ('\n'.join(
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
348 ['Unexpected bake output. Left is expected output, '
1142
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
349 'right is actual output.'] +
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
350 excinfo.value.args[0]))
398
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
351 elif isinstance(excinfo.value, BakeError):
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
352 res = ('\n'.join(
398
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
353 ['Errors occured during bake:'] +
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
354 excinfo.value.args[0]))
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
355 res += repr_nested_failure(excinfo)
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
356 return res
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
357 return super(BakeTestItem, self).repr_failure(excinfo)
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
358
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
359
398
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
360 class BakeError(Exception):
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
361 pass
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
362
af17c143b9ab tests: Fail bake tests with a proper error message when bake fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 397
diff changeset
363
1126
be550e1f6423 tests: Improve failure reporting, improve CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1096
diff changeset
364 class UnexpectedBakeOutputError(Exception):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
365 pass
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
366
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
367
385
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
368 class BakeTestFile(YamlTestFileBase):
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
369 __item_class__ = BakeTestItem
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
370
2d5f2289885a tests: Add support for "Chef tests", which are direct CLI tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 365
diff changeset
371
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
372 class ServeTestItem(YamlTestItemBase):
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
373 def runtest(self):
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
374 fs = self._prepareMockFs()
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
375
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
376 url = self.spec.get('url')
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
377 if url is None:
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
378 raise Exception("Missing URL in test spec.")
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
379
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
380 expected_status = self.spec.get('status', 200)
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
381 expected_headers = self.spec.get('headers')
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
382 expected_output = self.spec.get('out')
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
383 expected_contains = self.spec.get('out_contains')
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
384
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
385 from werkzeug.test import Client
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
386 from werkzeug.wrappers import BaseResponse
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
387 from piecrust.app import PieCrustFactory
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
388 from piecrust.serving.server import PieCrustServer
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
389
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
390 with mock_fs_scope(fs, keep=self.mock_debug):
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
391 appfactory = PieCrustFactory(
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
392 fs.path('/kitchen'),
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
393 theme_site=self.is_theme_site)
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
394 server = PieCrustServer(appfactory)
775
ba0a6bd5e913 tests: Make it possible to run FoodTruck tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 674
diff changeset
395
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
396 client = Client(server, BaseResponse)
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
397 resp = client.get(url)
1096
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
398 if expected_status != resp.status_code:
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
399 raise UnexpectedChefServingError(
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
400 url,
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
401 "Expected HTTP status '%s', got '%s'" %
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
402 (expected_status, resp.status_code),
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
403 resp)
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
404
1142
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
405 cctx = CompareContext()
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
406
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
407 if expected_headers:
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
408 for k, v in expected_headers.items():
1142
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
409 cmpres = _compare_str(v, resp.headers.get(k), cctx)
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
410 if cmpres:
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
411 raise UnexpectedChefServingOutput(cmpres)
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
412
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
413 actual = resp.data.decode('utf8').rstrip()
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
414 if expected_output:
1142
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
415 cmpres = _compare_str(expected_output.rstrip(), actual, cctx)
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
416 if cmpres:
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
417 raise UnexpectedChefServingOutput(cmpres)
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
418
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
419 if expected_contains:
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
420 assert expected_contains.rstrip() in actual
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
421
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
422 def reportinfo(self):
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
423 return self.fspath, 0, "serve: %s" % self.name
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
424
520
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
425 def repr_failure(self, excinfo):
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
426 from piecrust.serving.server import MultipleNotFound
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
427 if isinstance(excinfo.value, MultipleNotFound):
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
428 res = '\n'.join(
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
429 ["HTTP error 404 returned:",
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
430 str(excinfo.value)] +
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
431 [str(e) for e in excinfo.value._nfes])
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
432 res += repr_nested_failure(excinfo)
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
433 return res
520
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
434 elif isinstance(excinfo.value, HTTPException):
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
435 res = '\n'.join(
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
436 ["HTTP error %s returned:" % excinfo.value.code,
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
437 excinfo.value.description])
673
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
438 res += repr_nested_failure(excinfo)
d6403c21bdea tests: Improve failure reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
439 return res
1096
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
440 elif isinstance(excinfo.value, UnexpectedChefServingError):
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
441 res = str(excinfo.value)
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
442 res += '\nWhile requesting URL: %s' % excinfo.value.url
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
443 res += '\nBody:\n%s' % excinfo.value.resp.data.decode('utf8')
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
444 return res
1142
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
445 elif isinstance(excinfo.value, UnexpectedChefServingOutput):
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
446 res = '\n'.join(
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
447 ["Unexpected serving output. Left is expected output, "
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
448 "right is actual output."] +
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
449 excinfo.value.args[0])
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
450 return res
520
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
451 return super(ServeTestItem, self).repr_failure(excinfo)
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
452
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
453
1096
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
454 class UnexpectedChefServingError(Exception):
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
455 def __init__(self, url, msg, resp):
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
456 super().__init__(msg)
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
457 self.url = url
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
458 self.resp = resp
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
459
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
460
1142
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
461 class UnexpectedChefServingOutput(Exception):
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
462 pass
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
463
952f3c24a99d tests: Improve servings tests' error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents: 1126
diff changeset
464
391
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
465 class ServeTestFile(YamlTestFileBase):
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
466 __item_class__ = ServeTestItem
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
467
3e4bb57d8506 tests: Add support for testing the Chef server.
Ludovic Chabant <ludovic@chabant.com>
parents: 385
diff changeset
468
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
469 def _add_mock_files(fs, parent_path, spec):
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
470 for name, subspec in spec.items():
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
471 path = os.path.join(parent_path, name)
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
472 if isinstance(subspec, str):
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
473 fs.withFile(path, subspec)
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
474 elif isinstance(subspec, dict):
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
475 _add_mock_files(fs, path, subspec)
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
476
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
477
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
478 class CompareContext(object):
439
c0700c6d9545 tests: Fix crash in processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 436
diff changeset
479 def __init__(self, path=None, t=None):
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
480 self.path = path or ''
439
c0700c6d9545 tests: Fix crash in processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 436
diff changeset
481 self.time = t or time.time()
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
482
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
483 def createChildContext(self, name):
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
484 ctx = CompareContext(
974
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
485 path='%s/%s' % (self.path, name),
72f17534d58e tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 806
diff changeset
486 t=self.time)
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
487 return ctx
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
488
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
489
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
490 def _compare(left, right, ctx):
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
491 if type(left) != type(right):
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
492 return (["Different items: ",
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
493 "%s: %s" % (ctx.path, pprint.pformat(left)),
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
494 "%s: %s" % (ctx.path, pprint.pformat(right))])
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
495 if isinstance(left, str):
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
496 return _compare_str(left, right, ctx)
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
497 elif isinstance(left, dict):
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
498 return _compare_dicts(left, right, ctx)
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
499 elif isinstance(left, list):
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
500 return _compare_lists(left, right, ctx)
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
501 elif left != right:
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
502 return (["Different items: ",
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
503 "%s: %s" % (ctx.path, pprint.pformat(left)),
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
504 "%s: %s" % (ctx.path, pprint.pformat(right))])
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
505
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
506
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
507 def _compare_dicts(left, right, ctx):
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
508 key_diff = set(left.keys()) ^ set(right.keys())
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
509 if key_diff:
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
510 extra_left = set(left.keys()) - set(right.keys())
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
511 if extra_left:
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
512 return (["Left contains more items: "] +
520
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
513 ['- %s/%s' % (ctx.path, k) for k in extra_left] +
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
514 ['Left:', ', '.join(left.keys())] +
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
515 ['Right:', ', '.join(right.keys())])
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
516 extra_right = set(right.keys()) - set(left.keys())
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
517 if extra_right:
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
518 return (["Right contains more items: "] +
520
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
519 ['- %s/%s' % (ctx.path, k) for k in extra_right] +
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
520 ['Left:', ', '.join(left.keys())] +
bab91fcef741 bake/serve: Improve support for unicode, add slugification options.
Ludovic Chabant <ludovic@chabant.com>
parents: 493
diff changeset
521 ['Right:', ', '.join(right.keys())])
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
522 return ["Unknown difference"]
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
523
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
524 for key in left.keys():
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
525 lv = left[key]
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
526 rv = right[key]
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
527 child_ctx = ctx.createChildContext(key)
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
528 cmpres = _compare(lv, rv, child_ctx)
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
529 if cmpres:
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
530 return cmpres
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
531 return None
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
532
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
533
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
534 def _compare_lists(left, right, ctx):
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
535 for i in range(min(len(left), len(right))):
1096
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
536 lc = left[i]
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
537 rc = right[i]
2aa6174453c8 tests: Better error reporting for serving tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 1028
diff changeset
538 cmpres = _compare(lc, rc, ctx)
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
539 if cmpres:
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
540 return cmpres
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
541 if len(left) > len(right):
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
542 return (["Left '%s' contains more items. First extra item: " %
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
543 ctx.path, left[len(right)]])
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
544 if len(right) > len(left):
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
545 return (["Right '%s' contains more items. First extra item: " %
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
546 ctx.path, right[len(left)]])
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
547 return None
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
548
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
549
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
550 def _compare_str(left, right, ctx):
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
551 if left == right:
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
552 return None
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
553
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
554 test_time_iso8601 = time.strftime('%Y-%m-%dT%H:%M:%SZ',
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
555 time.gmtime(ctx.time))
582
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
556 test_time_iso8601_pattern = '%test_time_iso8601%'
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
557
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
558 left_time_indices = []
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
559 i = -1
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
560 while True:
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
561 i = left.find(test_time_iso8601_pattern, i + 1)
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
562 if i >= 0:
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
563 left_time_indices.append(i)
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
564 left = (left[:i] + test_time_iso8601 +
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
565 left[i + len(test_time_iso8601_pattern):])
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
566 else:
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
567 break
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
568
665
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
569 skip_for = -1
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
570 for i in range(min(len(left), len(right))):
665
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
571 if skip_for > 0:
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
572 skip_for -= 1
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
573 continue
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
574
582
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
575 if i in left_time_indices:
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
576 # This is where the time starts. Let's compare that the time
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
577 # values are within a few seconds of each other (usually 0 or 1).
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
578 right_time_str = right[i:i + len(test_time_iso8601)]
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
579 right_time = time.strptime(right_time_str, '%Y-%m-%dT%H:%M:%SZ')
806
8ac2d6045d1d tests: Fix for time comparisons.
Ludovic Chabant <ludovic@chabant.com>
parents: 788
diff changeset
580 left_time = time.gmtime(ctx.time)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
581 # Need to patch the daylist-savings-time flag because it can
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
582 # mess up the computation of the time difference.
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
583 right_time = (right_time[0], right_time[1], right_time[2],
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
584 right_time[3], right_time[4], right_time[5],
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
585 right_time[6], right_time[7],
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
586 left_time.tm_isdst)
582
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
587 difference = time.mktime(left_time) - time.mktime(right_time)
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
588 print("Got time difference: %d" % difference)
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 974
diff changeset
589 if abs(difference) <= 1:
582
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
590 print("(good enough, moving to end of timestamp)")
665
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
591 skip_for = len(test_time_iso8601) - 1
582
d8d9e0424a72 tests: Fix (hopefully) time-sensitive tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 567
diff changeset
592
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
593 if left[i] != right[i]:
365
a9929e0b8f66 tests: Changes to output report and hack for comparing outputs.
Ludovic Chabant <ludovic@chabant.com>
parents: 351
diff changeset
594 start = max(0, i - 15)
399
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
595 l_end = min(len(left), i + 15)
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
596 r_end = min(len(right), i + 15)
365
a9929e0b8f66 tests: Changes to output report and hack for comparing outputs.
Ludovic Chabant <ludovic@chabant.com>
parents: 351
diff changeset
597
399
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
598 l_str = ''
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
599 l_offset = 0
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
600 for j in range(start, l_end):
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
601 c = repr(left[j]).strip("'")
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
602 l_str += c
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
603 if j < i:
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
604 l_offset += len(c)
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
605
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
606 r_str = ''
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
607 r_offset = 0
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
608 for j in range(start, r_end):
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
609 c = repr(right[j]).strip("'")
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
610 r_str += c
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
611 if j < i:
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
612 r_offset += len(c)
365
a9929e0b8f66 tests: Changes to output report and hack for comparing outputs.
Ludovic Chabant <ludovic@chabant.com>
parents: 351
diff changeset
613
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
614 return ["Items '%s' differ at index %d:" % (ctx.path, i), '',
365
a9929e0b8f66 tests: Changes to output report and hack for comparing outputs.
Ludovic Chabant <ludovic@chabant.com>
parents: 351
diff changeset
615 "Left:", left, '',
a9929e0b8f66 tests: Changes to output report and hack for comparing outputs.
Ludovic Chabant <ludovic@chabant.com>
parents: 351
diff changeset
616 "Right:", right, '',
a9929e0b8f66 tests: Changes to output report and hack for comparing outputs.
Ludovic Chabant <ludovic@chabant.com>
parents: 351
diff changeset
617 "Difference:",
399
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
618 l_str, (' ' * l_offset + '^'),
a0724af26c12 tests: More accurate marker position for diff'ing strings.
Ludovic Chabant <ludovic@chabant.com>
parents: 398
diff changeset
619 r_str, (' ' * r_offset + '^')]
665
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
620
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
621 if len(left) > len(right):
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
622 return ["Left is longer.",
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
623 "Left '%s': " % ctx.path, left,
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
624 "Right '%s': " % ctx.path, right,
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
625 "Extra items: %r" % left[len(right):]]
665
5dc13c816045 tests: Fix logic for making time-based tests not fail randomly.
Ludovic Chabant <ludovic@chabant.com>
parents: 583
diff changeset
626
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
627 if len(right) > len(left):
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
628 return ["Right is longer.",
436
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
629 "Left '%s': " % ctx.path, left,
2aa879d63133 tests: Add pipeline processing tests.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
630 "Right '%s': " % ctx.path, right,
351
1f22d4b10fef tests: Improve bake tests output, add support for partial output checks.
Ludovic Chabant <ludovic@chabant.com>
parents: 347
diff changeset
631 "Extra items: %r" % right[len(left):]]
347
76c838453dbe tests: Support for YAML-based baking tests. Convert old code-based ones.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
632
1169
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
633
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
634 re_pyver_cond = re.compile(r'^\{py(?P<cmp>[\<\>\=]\=?)(?P<ver>[\d\.]+)\}')
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
635
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
636 _cur_pyver = (sys.version_info.major, sys.version_info.minor,
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
637 sys.version_info.micro)
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
638
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
639
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
640 def _eval_pyversion_condition(string):
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
641 m = re_pyver_cond.match(string)
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
642 if m is None:
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
643 return string, True
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
644
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
645
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
646 pyver_bits = m.group('ver').split('.')
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
647 while len(pyver_bits) < 3:
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
648 pyver_bits.append('0')
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
649 cmp_ver = tuple([int(b) for b in pyver_bits])
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
650
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
651 cmp_op = m.group('cmp')
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
652 if cmp_op == '>':
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
653 res = _cur_pyver > cmp_ver
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
654 elif cmp_op == '>=':
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
655 res = _cur_pyver >= cmp_ver
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
656 elif cmp_op == '<':
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
657 res = _cur_pyver < cmp_ver
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
658 elif cmp_op == '<=':
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
659 res = _cur_pyver <= cmp_ver
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
660 elif cmp_op == '==':
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
661 res = _cur_pyver == cmp_ver
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
662 else:
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
663 raise Exception("Unknown comparison operator: %s" % cmp_op)
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
664
978ed6deea91 tests: Add ability to test different expected outputs based on Python version.
Ludovic Chabant <ludovic@chabant.com>
parents: 1160
diff changeset
665 return string[m.end():], res