def test_hashing(): x = FakeFactory('email') assert hash(x) == hash(FakeFactory('email')) y = FakeFactory('email', locale='en_US') assert hash(x) != hash(y) d = {x: x, y: y} assert d[x] == x assert d[y] == y
import logging import hypothesis import tempfile import string from hypothesis.extra.fakefactory import FakeFactory from playhouse.test_utils import test_database from peewee import SqliteDatabase test_db = SqliteDatabase(':memory:') def makePath(s): return s.split('://', 1)[1].split('/', 1)[1] Path = hypothesis.strategy(FakeFactory('url')).map(makePath) FullUrl = hypothesis.strategy(FakeFactory('url')) Domain = hypothesis.strategy(FakeFactory('domain_name')) class SoftlinkParsingTestCase(unittest.TestCase): @hypothesis.given(Path) def test_parser_no_refer(self, s): req = werkzeug.test.EnvironBuilder(path=s) resp = model.Page.parsePreviousSlugFromRequest(req, 'index') self.assertEqual(req.lastSlug, None) @hypothesis.given(Path, FullUrl) def test_parser_extern_refer(self, page, refer):
def test_can_get_specification_for_fake_factory(): ff = FakeFactory('email') strategy(ff)
def test_equality(): assert FakeFactory('email') == FakeFactory('email') assert FakeFactory('email') != FakeFactory('name') assert FakeFactory('email') != FakeFactory('email', locale='en_US')
def test_fake_factory_errors_if_unsupported_method(): with pytest.raises(ValueError): FakeFactory('spoon')
def test_fake_factory_errors_if_private_ish_method(): with pytest.raises(ValueError): FakeFactory('_Generator__config')
def test_fake_factory_errors_with_unsupported_locale(): with pytest.raises(ValueError): FakeFactory('name', locale='badger_BADGER')
def test_fake_factory_errors_if_any_locale_is_unsupported(): with pytest.raises(ValueError): FakeFactory('name', locales=['fr_FR', 'en_US', 'mushroom_MUSHROOM'])
def test_fake_factory_errors_with_both_locale_and_locales(): with pytest.raises(ValueError): FakeFactory('name', locale='fr_FR', locales=['fr_FR', 'en_US'])
def test_french_names_may_have_an_accent(): Verifier().falsify(lambda x: 'é' not in x, FakeFactory('name', locale='fr_FR'))
import pytest from hypothesis import given from faker.providers import BaseProvider from hypothesis.strategytests import strategy_test_suite from hypothesis.searchstrategy import strategy from hypothesis.extra.fakefactory import FakeFactory from hypothesis.internal.verifier import Verifier class KittenProvider(BaseProvider): def kittens(self): return 'meow %d' % (self.random_number(digits=10), ) @given(FakeFactory('kittens', providers=[KittenProvider])) def test_kittens_meow(kitten): assert 'meow' in kitten @given(FakeFactory('email')) def test_email(email): assert '@' in email @given(FakeFactory('name', locale='en_US')) def test_english_names_are_ascii(name): name.encode('ascii') def test_french_names_may_have_an_accent():
from spacewiki import model import unittest import hypothesis import string import tempfile from hypothesis.extra.fakefactory import FakeFactory from spacewiki.app import create_app from playhouse.test_utils import test_database from peewee import SqliteDatabase test_db = SqliteDatabase(':memory:') def makePath(s): return s.split('://', 1)[1].split('/', 1)[1] Path = hypothesis.strategy(FakeFactory('url')).map(makePath) class SlugTestCase(unittest.TestCase): def setUp(self): self._app = create_app() self._app.config['DATABASE_URL'] = 'sqlite:///:memory:' self._app.secret_key = 'foo' self.app = self._app.test_client() def test_split_title(self): self.assertEqual(SlugField.split_title('foo'), ('', 'foo')) self.assertEqual(SlugField.split_title('foo/bar'), ('foo', 'bar')) def test_mangle_slug(self): self.assertEqual(SlugField.mangle_full_slug('foo/bar', 'Bar'), ('foo/bar/', 'Bar'))
def test_french_names_may_have_an_accent(): minimal(FakeFactory('name', locale='fr_FR'), lambda x: 'é' not in x)