/
test_simple_characters.py
69 lines (44 loc) · 2.2 KB
/
test_simple_characters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# coding=utf-8
# This file is part of Hypothesis (https://github.com/DRMacIver/hypothesis)
# Most of this work is copyright (C) 2013-2015 David R. MacIver
# (david@drmaciver.com), but it contains contributions by others. See
# https://github.com/DRMacIver/hypothesis/blob/master/CONTRIBUTING.rst for a
# full list of people who may hold copyright, and consult the git log if you
# need to determine who owns an individual contribution.
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
# END HEADER
from __future__ import division, print_function, absolute_import
import unicodedata
import pytest
from hypothesis import find
from hypothesis.errors import NoSuchExample
from hypothesis.strategies import characters
from hypothesis.searchstrategy.misc import SampledFromStrategy
def test_default_excludes_surrogates():
with pytest.raises(NoSuchExample):
find(characters(), lambda c: unicodedata.category(c) == 'Cs')
def test_exact_characters_is_sampled_from():
assert isinstance(
characters(exact='abc').wrapped_strategy.wrapped_strategy,
SampledFromStrategy)
def test_exclude_specific_characters():
st = characters(exact='123', exclude=True)
with pytest.raises(NoSuchExample):
find(st, lambda c: c in '123')
def test_characters_of_specific_groups():
st = characters(categories=('Lu', 'Nd'))
find(st, lambda c: unicodedata.category(c) == 'Lu')
find(st, lambda c: unicodedata.category(c) == 'Nd')
with pytest.raises(NoSuchExample):
find(st, lambda c: unicodedata.category(c) not in ('Lu', 'Nd'))
def test_exclude_characters_of_specific_groups():
st = characters(categories=('Lu', 'Nd'), exclude=True)
find(st, lambda c: unicodedata.category(c) != 'Lu')
find(st, lambda c: unicodedata.category(c) != 'Nd')
with pytest.raises(NoSuchExample):
find(st, lambda c: unicodedata.category(c) in ('Lu', 'Nd'))
def test_can_find_exact_character_with_foreign_unicode_category():
st = characters(exact='a', categories=['Nd'])
assert 'a' == find(st, lambda c: unicodedata.category(c) == 'Ll')