comparison tests/conftest.py @ 520:bab91fcef741

bake/serve: Improve support for unicode, add slugification options. * Add slugification options for taxonomies. * Sort out some unicode support problems on OSX. * Add tests.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 28 Jul 2015 18:34:21 -0700
parents 95b77239c3b7
children 1f37f66204b8
comparison
equal deleted inserted replaced
519:9d1a89cd8146 520:bab91fcef741
5 import os.path 5 import os.path
6 import logging 6 import logging
7 import pytest 7 import pytest
8 import yaml 8 import yaml
9 import colorama 9 import colorama
10 from werkzeug.exceptions import HTTPException
10 from piecrust.app import apply_variant_and_values 11 from piecrust.app import apply_variant_and_values
11 from piecrust.configuration import merge_dicts 12 from piecrust.configuration import merge_dicts
12 from .mockutil import mock_fs, mock_fs_scope 13 from .mockutil import mock_fs, mock_fs_scope
13 14
14 15
320 if expected_contains: 321 if expected_contains:
321 assert expected_contains.rstrip() in actual 322 assert expected_contains.rstrip() in actual
322 323
323 def reportinfo(self): 324 def reportinfo(self):
324 return self.fspath, 0, "serve: %s" % self.name 325 return self.fspath, 0, "serve: %s" % self.name
326
327 def repr_failure(self, excinfo):
328 from piecrust.serving.server import MultipleNotFound
329 if isinstance(excinfo.value, MultipleNotFound):
330 return '\n'.join(
331 ["HTTP error 404 returned:",
332 excinfo.value.description] +
333 [e.description for e in excinfo.value._nfes])
334 elif isinstance(excinfo.value, HTTPException):
335 return '\n'.join(
336 ["HTTP error %s returned:" % excinfo.value.code,
337 excinfo.value.description])
338 return super(ServeTestItem, self).repr_failure(excinfo)
325 339
326 340
327 class ServeTestFile(YamlTestFileBase): 341 class ServeTestFile(YamlTestFileBase):
328 __item_class__ = ServeTestItem 342 __item_class__ = ServeTestItem
329 343
370 key_diff = set(left.keys()) ^ set(right.keys()) 384 key_diff = set(left.keys()) ^ set(right.keys())
371 if key_diff: 385 if key_diff:
372 extra_left = set(left.keys()) - set(right.keys()) 386 extra_left = set(left.keys()) - set(right.keys())
373 if extra_left: 387 if extra_left:
374 return (["Left contains more items: "] + 388 return (["Left contains more items: "] +
375 ['- %s/%s' % (ctx.path, k) for k in extra_left]) 389 ['- %s/%s' % (ctx.path, k) for k in extra_left] +
390 ['Left:', ', '.join(left.keys())] +
391 ['Right:', ', '.join(right.keys())])
376 extra_right = set(right.keys()) - set(left.keys()) 392 extra_right = set(right.keys()) - set(left.keys())
377 if extra_right: 393 if extra_right:
378 return (["Right contains more items: "] + 394 return (["Right contains more items: "] +
379 ['- %s/%s' % (ctx.path, k) for k in extra_right]) 395 ['- %s/%s' % (ctx.path, k) for k in extra_right] +
396 ['Left:', ', '.join(left.keys())] +
397 ['Right:', ', '.join(right.keys())])
380 return ["Unknown difference"] 398 return ["Unknown difference"]
381 399
382 for key in left.keys(): 400 for key in left.keys():
383 lv = left[key] 401 lv = left[key]
384 rv = right[key] 402 rv = right[key]