Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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') |