コード例 #1
0
ファイル: tests.py プロジェクト: pombredanne/vargas
def test_tempo_should_descrever_quando_difereca_de_tempo_ocorreu_ha_1_mes_atras_com_31_dias():
    u"TempoRelativo deveria descrever quando diferenca de tempo ocorreu ha 1 mês atras"
    relative_time = datetime.now() - timedelta(minutes=60 * 24 * 31)
    decorrido = TempoRelativo(relative_time)
    assert that(decorrido.ha).equals(u"há 1 mês")
    assert that(decorrido.atras).equals(u"1 mês atrás")
    assert that(unicode(decorrido)).equals(u"há 1 mês")
コード例 #2
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_by_attribute_id(context):
    "selecting by attribute (id)"
    dom = DOM(context.html)

    (body, ) = dom.find("[id=firstp]")
    assert that(body).is_a(Element)
    assert that(body.attribute['id']).equals("firstp")
コード例 #3
0
ファイル: tests.py プロジェクト: pombredanne/vargas
def test_tempo_should_descrever_quando_difereca_de_tempo_ocorreu_ha_55_minutos_atras():
    u"TempoRelativo deveria descrever quando diferenca de tempo ocorreu ha 55 minutos atras"
    relative_time = datetime.now() - timedelta(minutes=55)
    decorrido = TempoRelativo(relative_time)
    assert that(decorrido.ha).equals(u"há 55 minutos")
    assert that(decorrido.atras).equals(u"55 minutos atrás")
    assert that(unicode(decorrido)).equals(u"há 55 minutos")
コード例 #4
0
def test_that_something_iterable_matches_another():
    "sure.that(something_iterable).matches(another_iterable)"

    KlassOne = type('KlassOne', (object, ), {})
    KlassTwo = type('KlassTwo', (object, ), {})
    one = [
        ("/1", KlassOne),
        ("/2", KlassTwo),
    ]

    two = [
        ("/1", KlassOne),
        ("/2", KlassTwo),
    ]

    assert that(one).matches(two)
    assert that(one).equals(two)

    def fail_1():
        assert that(range(1)).matches(xrange(2))

    class Fail2(object):
        def __init__(self):
            assert that(xrange(1)).equals(range(2))

    class Fail3(object):
        def __call__(self):
            assert that(xrange(1)).equals(range(2))

    assert that(fail_1).raises('[0] has 1 item, but xrange(2) has 2 items')
    assert that(Fail2).raises('xrange(1) has 1 item, but [0, 1] has 2 items')
    assert that(Fail3()).raises('xrange(1) has 1 item, but [0, 1] has 2 items')
コード例 #5
0
ファイル: test_old_api.py プロジェクト: e0ne/sure
def test_that_something_iterable_matches_another():
    "sure.that(something_iterable).matches(another_iterable)"

    KlassOne = type('KlassOne', (object,), {})
    KlassTwo = type('KlassTwo', (object,), {})
    one = [
        ("/1", KlassOne),
        ("/2", KlassTwo),
    ]

    two = [
        ("/1", KlassOne),
        ("/2", KlassTwo),
    ]

    assert that(one).matches(two)
    assert that(one).equals(two)

    def fail_1():
        assert that(range(1)).matches(xrange(2))

    class Fail2(object):
        def __init__(self):
            assert that(xrange(1)).matches(range(2))

    class Fail3(object):
        def __call__(self):
            assert that(xrange(1)).matches(range(2))

    assert that(fail_1).raises('X is a list and Y is a xrange instead')
    assert that(Fail2).raises('X is a xrange and Y is a list instead')
    assert that(Fail3()).raises('X is a xrange and Y is a list instead')
コード例 #6
0
def test_have_property_with_value():
    (u"this(instance).should.have.property(property_name).being or "
     ".with_value should allow chain up")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return ur"Person()"

    jay = Person()

    assert this(jay).should.have.property("name").being.equal("John Doe")
    assert this(jay).should.have.property("name").not_being.equal("Foo")

    def opposite():
        assert this(jay).should.have.property("name").not_being.equal(
            "John Doe")

    def opposite_not():
        assert this(jay).should.have.property("name").being.equal(
            "Foo")

    assert that(opposite).raises(AssertionError)
    assert that(opposite).raises(
        "'John Doe' should differ to 'John Doe', but is the same thing")

    assert that(opposite_not).raises(AssertionError)
    assert that(opposite_not).raises(
        "X is 'John Doe' whereas Y is 'Foo'")
コード例 #7
0
def test_httpretty_should_mock_headers_requests(now):
    u"HTTPretty should mock basic headers with requests"

    HTTPretty.register_uri(HTTPretty.GET,
                           "http://github.com/",
                           body="this is supposed to be the response",
                           status=201)

    response = requests.get('http://github.com')
    assert that(response.status_code).equals(201)

    assert that(dict(response.headers)).equals({
        'content-type':
        'text/plain; charset=utf-8',
        'connection':
        'close',
        'content-length':
        '35',
        'status':
        '201',
        'server':
        'Python/HTTPretty',
        'date':
        now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
    })
コード例 #8
0
ファイル: test_usage.py プロジェクト: gabrielfalcao/github-py
def test_second_authentication_step_takes_code_and_makes_a_request(context):
    "github.API's second authentication step is a redirect"

    class MyStore(github.TokenStore):
        data = {}

        def set(self, k, v):
            self.data[k] = v

        def get(self, k):
            return self.data.get(k)

    simple = MyStore()
    api = github.API("app-id-here", "app-secret-here", store=simple)

    HTTPretty.register_uri(
        HTTPretty.POST,
        "https://github.com/login/oauth/access_token",
        body='{"access_token": "this-is-the-access-token"}',
        status=200,
    )

    result = api.authenticate(code="visitor-code")
    assert that(result).is_a(github.API)

    last_request = HTTPretty.last_request
    assert that(last_request.headers).has("Authentication")
コード例 #9
0
def test_have_property():
    (u"this(instance).should.have.property(property_name)")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return ur"Person()"

    jay = Person()

    assert this(jay).should.have.property("name")
    assert this(jay).should_not.have.property("age")

    def opposite():
        assert this(jay).should_not.have.property("name")

    def opposite_not():
        assert this(jay).should.have.property("age")

    assert that(opposite).raises(AssertionError)
    assert that(opposite).raises(
        "Person() should not have the property `name`, but it is 'John Doe'")

    assert that(opposite_not).raises(AssertionError)
    assert that(opposite_not).raises(
        "Person() should have the property `age` but doesn't")
コード例 #10
0
ファイル: test_sure.py プロジェクト: pjdelport/sure
def test_that_something_iterable_matches_another():
    "sure.that(something_iterable).matches(another_iterable)"

    KlassOne = type('KlassOne', (object,), {})
    KlassTwo = type('KlassTwo', (object,), {})
    one = [
        ("/1", KlassOne),
        ("/2", KlassTwo),
    ]

    two = [
        ("/1", KlassOne),
        ("/2", KlassTwo),
    ]

    assert that(one).matches(two)
    assert that(one).equals(two)

    def fail_1():
        assert that(range(1)).matches(xrange(2))

    class Fail2(object):
        def __init__(self):
            assert that(xrange(1)).equals(range(2))

    class Fail3(object):
        def __call__(self):
            assert that(xrange(1)).equals(range(2))

    assert that(fail_1).raises('[0] has 1 item, but xrange(2) has 2 items')
    assert that(Fail2).raises('xrange(1) has 1 item, but [0, 1] has 2 items')
    assert that(Fail3()).raises('xrange(1) has 1 item, but [0, 1] has 2 items')
コード例 #11
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_by_id(context):
    "selecting by id"
    dom = DOM(context.html)

    body = dom.find("#firstp").first()
    assert that(body).is_a(Element)
    assert that(body.attribute['id']).equals("firstp")
コード例 #12
0
ファイル: tests.py プロジェクト: wpjunior/vargas
def test_tempo_should_descrever_quando_difereca_de_tempo_ocorreu_ha_menos_de_1_minuto_atras():
    u"TempoRelativo deveria descrever quando difereça de tempo ocorreu ha menos de 1 minuto atras"
    relative_time = datetime.now() - timedelta(seconds=55)
    decorrido = TempoRelativo(relative_time)
    assert that(decorrido.ha).equals(u"há menos de um minuto")
    assert that(decorrido.atras).equals(u"alguns segundos atrás")
    assert that(unicode(decorrido)).equals(u"há menos de um minuto")
コード例 #13
0
def test_assertion_builder_synonyms():
    (u"this, it, these and those are all synonyms")

    assert that(it).is_a(AssertionBuilder)
    assert that(this).is_a(AssertionBuilder)
    assert that(these).is_a(AssertionBuilder)
    assert that(those).is_a(AssertionBuilder)
コード例 #14
0
ファイル: test_bypass.py プロジェクト: nsigustavo/HTTPretty
def test_httpretty_bypasses_when_disabled():
    u"HTTPretty should bypass all requests by disabling it"

    HTTPretty.register_uri(HTTPretty.GET, "http://localhost:9999/go-for-bubbles/",
                           body="glub glub")

    HTTPretty.disable()

    fd = urllib2.urlopen('http://localhost:9999/go-for-bubbles/')
    got1 = fd.read()
    fd.close()

    assert that(got1).equals('. o O 0 O o . o O 0 O o . o O 0 O o . o O 0 O o . o O 0 O o .')

    fd = urllib2.urlopen('http://localhost:9999/come-again/')
    got2 = fd.read()
    fd.close()

    assert that(got2).equals('<- HELLO WORLD ->')

    HTTPretty.enable()

    fd = urllib2.urlopen('http://localhost:9999/go-for-bubbles/')
    got3 = fd.read()
    fd.close()

    assert that(got3).equals('glub glub')
コード例 #15
0
ファイル: tests.py プロジェクト: wpjunior/vargas
def test_tempo_should_descrever_quando_difereca_de_tempo_ocorreu_ha_1_hora_atras():
    u"TempoRelativo deveria descrever quando difereça de tempo ocorreu ha 1 hora atras"
    relative_time = datetime.now() - timedelta(minutes=60)
    decorrido = TempoRelativo(relative_time)
    assert that(decorrido.ha).equals(u"há 1 hora")
    assert that(decorrido.atras).equals(u"1 hora atrás")
    assert that(unicode(decorrido)).equals(u"há 1 hora")
コード例 #16
0
ファイル: tests.py プロジェクト: wpjunior/vargas
def test_tempo_should_descrever_quando_difereca_de_tempo_ocorreu_ha_1_minuto_e_meio_atras():
    u"TempoRelativo deveria descrever quando difereça de tempo ocorreu ha 1 minuto e meio atras"
    relative_time = datetime.now() - timedelta(seconds=90)
    decorrido = TempoRelativo(relative_time)
    assert that(decorrido.ha).equals(u"há pouco mais de 1 minuto")
    assert that(decorrido.atras).equals(u"1 minuto e 30 segundos atrás")
    assert that(unicode(decorrido)).equals(u"há pouco mais de 1 minuto")
コード例 #17
0
ファイル: test_breathalyzer.py プロジェクト: nyxtom/fbpuzzles
 def test_soundex_boundary(self):
     """
     Test case to ensure that the boundary cases of the soundex algorithm are handled appropriately.
     """
     assert that(self.runner.soundex('')).equals('0000')
     assert that(self.runner.soundex('   \r\n')).equals('0000')
     assert that(self.runner.soundex('3940')).equals('0000')
コード例 #18
0
ファイル: tests.py プロジェクト: wpjunior/vargas
def test_tempo_should_descrever_quando_difereca_de_tempo_ocorreu_ha_4_dias_atras():
    u"TempoRelativo deveria descrever quando difereça de tempo ocorreu ha 4 dias atras"
    relative_time = datetime.now() - timedelta(minutes=(60 * 24) * 4)
    decorrido = TempoRelativo(relative_time)
    assert that(decorrido.ha).equals(u"há 4 dias")
    assert that(decorrido.atras).equals(u"4 dias atrás")
    assert that(unicode(decorrido)).equals(u"há 4 dias")
コード例 #19
0
def test_httpretty_bypasses_when_disabled():
    u"HTTPretty should bypass all requests by disabling it"

    HTTPretty.register_uri(HTTPretty.GET,
                           "http://localhost:9999/go-for-bubbles/",
                           body="glub glub")

    HTTPretty.disable()

    fd = urllib2.urlopen('http://localhost:9999/go-for-bubbles/')
    got1 = fd.read()
    fd.close()

    assert that(got1).equals(
        '. o O 0 O o . o O 0 O o . o O 0 O o . o O 0 O o . o O 0 O o .')

    fd = urllib2.urlopen('http://localhost:9999/come-again/')
    got2 = fd.read()
    fd.close()

    assert that(got2).equals('<- HELLO WORLD ->')

    HTTPretty.enable()

    fd = urllib2.urlopen('http://localhost:9999/go-for-bubbles/')
    got3 = fd.read()
    fd.close()

    assert that(got3).equals('glub glub')
コード例 #20
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_html(context):
    "selecting html"
    dom = DOM(context.html)

    html = dom.get("html")
    assert that(html).is_a(Element)
    assert that(html.attribute['id']).equals("html")
コード例 #21
0
def see_the_right_stop_and_duration_time(step):
    stop_cell = world.wait_for_element('#stop-%s' % world.rows, 5, 0.5)
    assert that(stop_cell.text).equals(datetime.datetime.now().strftime("%B%e, %Y,%l:%M %P")), \
        'The stop time is not current'
    duration_cell = world.wait_for_element('#duration-%s' % world.rows, 5, 0.5)
    assert that(duration_cell.text).equals("00:00:03"), \
        'The duration is incorrect'
コード例 #22
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_by_class_with_many_classes(context):
    "selecting by many classes at once"
    dom = DOM(context.html)

    elements = dom.find("li.stuff.thing")
    assert that(elements).the_attribute('tag').equals('li')

    assert that(elements[0].attribute['id']).equals('house')
コード例 #23
0
def test_that_len_is():
    "sure.that() len_is(number)"

    lst = range(1000)

    assert that(lst).len_is(1000)
    assert len(lst) == 1000
    assert that(lst).len_is(lst)
コード例 #24
0
def attr_retrieves_each_attribute_by_name(context):
    "attr retrieves attributes each attribute by name"
    dom = DOM(context.html)

    ul = dom.find("#objects").first()

    assert that(ul.attr('id')).equals('objects')
    assert that(ul.attr('class')).equals('list no-bullets')
コード例 #25
0
ファイル: test_sure.py プロジェクト: pjdelport/sure
def test_that_len_is():
    "sure.that() len_is(number)"

    lst = range(1000)

    assert that(lst).len_is(1000)
    assert len(lst) == 1000
    assert that(lst).len_is(lst)
コード例 #26
0
def test_get_argv_options_integration(context):
    u"Nose should parse sys.argv and figure out whether to run as integration"
    sys.argv = ['./manage.py', 'test', '--integration']
    runner = Nose()

    opts = runner.get_argv_options()
    assert that(opts['is_unit']).equals(False)
    assert that(opts['is_functional']).equals(False)
    assert that(opts['is_integration']).equals(True)
コード例 #27
0
def test_that_len_lower_than():
    "sure.that() len_lower_than(number)"

    lst = range(100)
    lst2 = range(1000)

    assert that(lst).len_lower_than(101)
    assert len(lst) == 100
    assert that(lst).len_lower_than(lst2)
コード例 #28
0
ファイル: test_sure.py プロジェクト: pjdelport/sure
def test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher():
    u"that.is_a_matcher should absorb callables to be used as matcher"
    @that.is_a_matcher
    def is_truthful(what):
        assert bool(what), '{0} is so untrue'.format(what)
        return 'foobar'

    assert that('friend').is_truthful()
    assert_equals(that('friend').is_truthful(), 'foobar')
コード例 #29
0
ファイル: test_nose_runner.py プロジェクト: priestc/unclebob
def test_get_argv_options_simple(context):
    u"Nose should parse sys.argv"
    sys.argv = ['./manage.py', 'test']
    runner = Nose()

    opts = runner.get_argv_options()
    assert that(opts['is_unit']).equals(False)
    assert that(opts['is_functional']).equals(False)
    assert that(opts['is_integration']).equals(False)
コード例 #30
0
ファイル: test_nose_runner.py プロジェクト: priestc/unclebob
def test_get_argv_options_integration(context):
    u"Nose should parse sys.argv and figure out whether to run as integration"
    sys.argv = ['./manage.py', 'test', '--integration']
    runner = Nose()

    opts = runner.get_argv_options()
    assert that(opts['is_unit']).equals(False)
    assert that(opts['is_functional']).equals(False)
    assert that(opts['is_integration']).equals(True)
コード例 #31
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_by_class(context):
    "selecting by class name"
    dom = DOM(context.html)

    div = dom.find(".nothiddendiv").first()
    assert that(div).is_a(Element)
    assert that(div.attribute['id']).equals("nothiddendiv")
    assert that(div.attribute['style']).has("height:1px;")
    assert that(div.attribute['style']).has("background:white;")
コード例 #32
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_paragraphs(context):
    "selecting paragraphs"
    dom = DOM(context.html)

    identifiers = ["firstp", "ap", "sndp", "en", "sap", "first"]
    paragraphs = dom.find("p")

    assert that(dom).is_a(DOM)
    assert that(paragraphs).in_each("attribute['id']").matches(identifiers)
コード例 #33
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_by_child(context):
    "selecting by parent > child, mixing many kinds of selectors"
    dom = DOM(context.html)

    elements = dom.find(
        "ul#objects > li.geometry"
    )
    assert that(elements).in_each('tag').matches(['li', 'li'])
    assert that(elements).in_each("attribute['id']").matches(['ball', 'square'])
コード例 #34
0
ファイル: test_selectors.py プロジェクト: eroh92/dominic
def select_by_child_complex(context):
    "selecting by parent > child, mixing many kinds of selectors"
    dom = DOM(context.html)

    elements = dom.find(
        "div.ball.dog.square.house.puppet#like-this-one > ul#objects > li.geometry"
    )
    assert that(elements).in_each('tag').matches(['li', 'li'])
    assert that(elements).in_each("attribute['id']").matches(['ball', 'square'])
コード例 #35
0
ファイル: test_sure.py プロジェクト: pjdelport/sure
def test_that_len_lower_than():
    "sure.that() len_lower_than(number)"

    lst = range(100)
    lst2 = range(1000)

    assert that(lst).len_lower_than(101)
    assert len(lst) == 100
    assert that(lst).len_lower_than(lst2)
コード例 #36
0
def test_get_argv_options_simple(context):
    u"Nose should parse sys.argv"
    sys.argv = ['./manage.py', 'test']
    runner = Nose()

    opts = runner.get_argv_options()
    assert that(opts['is_unit']).equals(False)
    assert that(opts['is_functional']).equals(False)
    assert that(opts['is_integration']).equals(False)
コード例 #37
0
def test_tokenstore_set():
    "github.TokenStore.set is not implemented by default"

    store = github.TokenStore()
    assert that(store.set, with_args=['key-name']).raises(
        'github.TokenStore must be subclassed and the method ' \
        'set must be implemented',
    )
    assert that(store.set, with_args=['key-name']).raises(NotImplementedError)
コード例 #38
0
def test_backend_registry_find_definitions():
    "creating builders should be as easy as declaring classes"
    assert that(Registry.total()).equals(0)

    class Builder1(Registry):
        name = 'First'
        scheme = 'builder1://'

    assert that(Registry.total()).equals(1)
    assert that(Registry.get('builder1://')).equals(Builder1)
コード例 #39
0
def test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher():
    u"that.is_a_matcher should absorb callables to be used as matcher"

    @that.is_a_matcher
    def is_truthful(what):
        assert bool(what), '%s is so untrue' % (what)
        return 'foobar'

    assert that('friend').is_truthful()
    assert_equals(that('friend').is_truthful(), 'foobar')
コード例 #40
0
 def mock_get_paths_for(names, appending):
     k = expected_kinds.pop(0)
     assert that(names).is_a(list)
     assert that(appending).is_a(list)
     assert that(names).equals(['john', 'doe'])
     assert that(appending).equals(['tests', k])
     return [
         '/apps/john/tests/%s' % k,
         '/apps/doe/tests/%s' % k,
     ]
コード例 #41
0
def test_that_len_greater_than_should_raise_assertion_error():
    "sure.that() len_greater_than(number) raise AssertionError"

    lst = range(1000)
    try:
        that(lst).len_greater_than(1000)
    except AssertionError, e:
        assert_equals(
            str(e),
            'the length of the list should be greater then %d, but is %d'  \
            % (1000, 1000))
コード例 #42
0
def test_that_len_greater_than_or_equals():
    "sure.that() len_greater_than_or_equals(number)"

    lst = range(1000)
    lst2 = range(100)

    assert that(lst).len_greater_than_or_equals(100)
    assert that(lst).len_greater_than_or_equals(1000)
    assert len(lst) == 1000
    assert that(lst).len_greater_than_or_equals(lst2)
    assert that(lst).len_greater_than_or_equals(lst)
コード例 #43
0
def test_that_len_lower_than_or_equals_should_raise_assertion_error():
    "sure.that() len_lower_than_or_equals(number) raise AssertionError"

    lst = range(1000)
    try:
        that(lst).len_lower_than_or_equals(100)
    except AssertionError, e:
        assert_equals(
            str(e),
            'the length of %r should be lower then or equals %d, but is %d' % \
            (lst, 100, 1000))
コード例 #44
0
def test_httpretty_should_mock_a_simple_get_with_requests_read(now):
    u"HTTPretty should mock a simple GET with requests.get"

    HTTPretty.register_uri(HTTPretty.GET,
                           "http://yipit.com/",
                           body="Find the best daily deals")

    response = requests.get('http://yipit.com')
    assert that(response.text).equals('Find the best daily deals')
    assert that(HTTPretty.last_request.method).equals('GET')
    assert that(HTTPretty.last_request.path).equals('/')
コード例 #45
0
def test_httpretty_should_mock_a_simple_get_with_httplib2_read(now):
    u"HTTPretty should mock a simple GET with httplib2.context.http"

    HTTPretty.register_uri(HTTPretty.GET,
                           "http://yipit.com/",
                           body="Find the best daily deals")

    _, got = httplib2.Http().request('http://yipit.com', 'GET')
    assert that(got).equals('Find the best daily deals')
    assert that(HTTPretty.last_request.method).equals('GET')
    assert that(HTTPretty.last_request.path).equals('/')
コード例 #46
0
def test_httpretty_should_mock_a_simple_get_with_httplib2_read(now):
    u"HTTPretty should mock a simple GET with httplib2.context.http"

    HTTPretty.register_uri(HTTPretty.GET,
                           "http://globo.com/",
                           body="The biggest portal in Brazil")

    _, got = httplib2.Http().request('http://globo.com', 'GET')
    assert that(got).equals('The biggest portal in Brazil')
    assert that(HTTPretty.last_request.method).equals('GET')
    assert that(HTTPretty.last_request.path).equals('/')
コード例 #47
0
def test_that_at_key_equals():
    "sure.that().at(object).equals(object)"

    class Class:
        name = "some class"

    Object = Class()
    dictionary = {
        'name': 'John',
    }

    assert that(Class).at("name").equals('some class')
    assert that(Object).at("name").equals('some class')
    assert that(dictionary).at("name").equals('John')
コード例 #48
0
def test_single_scenario_many_scenarios():
    "Untagged scenario following a tagged one should have no tags"
    feature = Feature.from_string(FEATURE13)

    first_scenario = feature.scenarios[0]
    assert that(first_scenario.tags).equals(['runme'])

    second_scenario = feature.scenarios[1]
    assert that(second_scenario.tags).equals([])

    third_scenario = feature.scenarios[2]
    assert that(third_scenario.tags).equals(['slow'])

    last_scenario = feature.scenarios[3]
    assert that(last_scenario.tags).equals([])
コード例 #49
0
    def the_providers_are_working(Then):
        Then.the_context_has_variables()
        assert hasattr(Then, 'var1')
        assert hasattr(Then, 'foobar')
        assert hasattr(Then, '__sure_providers_of__')

        providers = Then.__sure_providers_of__
        action = Then.the_context_has_variables.__name__

        providers_of_var1 = [p.__name__ for p in providers['var1']]
        assert that(providers_of_var1).contains(action)

        providers_of_foobar = [p.__name__ for p in providers['foobar']]
        assert that(providers_of_foobar).contains(action)

        return True
コード例 #50
0
def test_that_contains_dictionary_keys():
    "sure.that(dict(name='foobar')).contains('name')"

    data = dict(name='foobar')
    assert 'name' in data
    assert 'name' in data.keys()
    assert that(data).contains('name')
コード例 #51
0
ファイル: test_sure.py プロジェクト: PiDelport/sure
def test_that_equals():
    "sure.that() equals(object)"

    something = "something"

    assert that(something).equals(something)
    assert something == something
コード例 #52
0
def test_that_checking_all_atributes_of_range():
    "sure.that(iterable, within_range=(1, 2)).the_attribute('name').equals('value')"

    class shape(object):
        def __init__(self, name):
            self.kind = 'geometrical form'
            self.name = name

        def __repr__(self):
            return '<%s:%s>' % (self.kind, self.name)

    shapes = [
        shape('circle'),
        shape('square'),
        shape('square'),
        shape('triangle'),
    ]

    assert shapes[0].name != 'square'
    assert shapes[3].name != 'square'

    assert shapes[1].name == 'square'
    assert shapes[2].name == 'square'

    assert that(shapes, within_range=(1, 2)). \
                           the_attribute("name"). \
                           equals('square')
コード例 #53
0
    def the_providers_are_working(Then):
        Then.the_context_has_variables('JohnDoe')
        assert hasattr(Then, 'var1')
        assert 'JohnDoe' in Then
        assert hasattr(Then, '__sure_providers_of__')

        providers = Then.__sure_providers_of__
        action = Then.the_context_has_variables.__name__

        providers_of_var1 = [p.__name__ for p in providers['var1']]
        assert that(providers_of_var1).contains(action)

        providers_of_JohnDoe = [p.__name__ for p in providers['JohnDoe']]
        assert that(providers_of_JohnDoe).contains(action)

        return True
コード例 #54
0
def test_deep_equals_dict_level3_fails_different_key():
    "sure.that() deep_equals(dict) failing on level 3 when has an extra key"

    something = {
        'my::all_users': [
            {
                'name': 'John',
                'age': 33,
                'foo': 'bar'
            },
        ],
    }

    def assertions():
        assert that(something).deep_equals({
            'my::all_users': [
                {
                    'name': 'John',
                    'age': 33,
                    'bar': 'foo'
                },
            ],
        })

    assert that(assertions).raises(
        AssertionError,
        "given\n" \
        "X = {'my::all_users': [{'age': 33, 'foo': 'bar', 'name': 'John'}]}\n" \
        "    and\n" \
        "Y = {'my::all_users': [{'age': 33, 'bar': 'foo', 'name': 'John'}]}\n" \
        "X['my::all_users'][0] has the key 'foo' whereas Y['my::all_users'][0] doesn't",
    )
コード例 #55
0
def test_that_equals():
    "sure.that() equals(string)"

    something = "something"

    assert that('something').equals(something)
    assert something == 'something'
コード例 #56
0
def test_that_differs():
    "sure.that() differs(object)"

    something = "something"

    assert that(something).differs("23123%FYTUGIHOfdf")
    assert something != "23123%FYTUGIHOfdf"
コード例 #57
0
def test_deep_equals_dict_level2_fail():
    "sure.that() deep_equals(dict) failing on level 2"

    something = {
        'one': 'yeah',
        'another': {
            'two': '##',
        },
    }

    def assertions():
        assert that(something).deep_equals({
            'one': 'yeah',
            'another': {
                'two': '$$',
            },
        })
    assert that(assertions).raises(
        AssertionError,
        "given\n" \
        "X = {'another': {'two': '##'}, 'one': 'yeah'}\n" \
        "    and\n" \
        "Y = {'another': {'two': '$$'}, 'one': 'yeah'}\n" \
        "X['another']['two'] is '##' whereas Y['another']['two'] is '$$'",
    )
コード例 #58
0
def test_that_is_a():
    "sure.that() is_a(object)"

    something = "something"

    assert that(something).is_a(str)
    assert isinstance(something, str)
コード例 #59
0
 def assertions():
     assert that(something).deep_equals({
         'one': 'yeah',
         'another': {
             'two': '$$',
         },
     })
コード例 #60
0
def test_deep_equals_dict_level3_fail_values():
    "sure.that() deep_equals(dict) failing on level 3"

    something = {
        'my::all_users': [
            {
                'name': 'John',
                'age': 33
            },
        ],
    }

    def assertions():
        assert that(something).deep_equals({
            'my::all_users': [
                {
                    'name': 'John',
                    'age': 30
                },
            ],
        })

    assert that(assertions).raises(
        AssertionError,
        "given\n" \
        "X = {'my::all_users': [{'age': 33, 'name': 'John'}]}\n" \
        "    and\n" \
        "Y = {'my::all_users': [{'age': 30, 'name': 'John'}]}\n" \
        "X['my::all_users'][0]['age'] is 33 whereas Y['my::all_users'][0]['age'] is 30",
    )