Example #1
0
def test_nil():
    nilaccept = NilAccept()
    eq_(repr(nilaccept),
        "<NilAccept: <class 'webob.acceptparse.Accept'>>"
    )
    assert not nilaccept
    assert str(nilaccept) == ''
    assert nilaccept.quality('dummy') == 0
def test_nil():
    nilaccept = NilAccept('Connection-Close')
    assert nilaccept.header_name == 'Connection-Close'
    eq_(repr(nilaccept),
        "<NilAccept for Connection-Close: <class 'webob.acceptparse.Accept'>>"
    )
    assert not nilaccept
    assert str(nilaccept) == ''
    assert nilaccept.quality('dummy') == 0
    assert nilaccept.best_matches() == []
    assert nilaccept.best_matches('foo') == ['foo']
Example #3
0
def test_nil_best_match():
    nilaccept = NilAccept()
    assert nilaccept.best_match(['foo', 'bar']) == 'foo'
    assert nilaccept.best_match([('foo', 1), ('bar', 0.5)]) == 'foo'
    assert nilaccept.best_match([('foo', 0.5), ('bar', 1)]) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar']) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar'],
                                default_match=True) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar'],
                                default_match=False) == 'bar'
    assert nilaccept.best_match([], default_match='fallback') == 'fallback'
Example #4
0
def test_nil_add():
    nilaccept = NilAccept()
    accept = Accept('text/html')
    assert nilaccept + accept is accept
    new_accept = nilaccept + nilaccept
    assert isinstance(new_accept, accept.__class__)
    assert new_accept.header_value == ''
    new_accept = nilaccept + 'foo'
    assert isinstance(new_accept, accept.__class__)
    assert new_accept.header_value == 'foo'
Example #5
0
def test_nil_best_match():
    nilaccept = NilAccept()
    assert nilaccept.best_match(["foo", "bar"]) == "foo"
    assert nilaccept.best_match([("foo", 1), ("bar", 0.5)]) == "foo"
    assert nilaccept.best_match([("foo", 0.5), ("bar", 1)]) == "bar"
    assert nilaccept.best_match([("foo", 0.5), "bar"]) == "bar"
    assert nilaccept.best_match([("foo", 0.5), "bar"], default_match=True) == "bar"
    assert nilaccept.best_match([("foo", 0.5), "bar"], default_match=False) == "bar"
    assert nilaccept.best_match([], default_match="fallback") == "fallback"
def test_nil_add():
    nilaccept = NilAccept('Connection-Close')
    accept = Accept('Content-Type', 'text/html')
    assert nilaccept + accept is accept
    new_accept = nilaccept + nilaccept
    assert isinstance(new_accept, accept.__class__)
    assert new_accept.header_name == 'Connection-Close'
    assert new_accept.header_value == ''
    new_accept = nilaccept + 'foo'
    assert isinstance(new_accept, accept.__class__)
    assert new_accept.header_name == 'Connection-Close'
    assert new_accept.header_value == 'foo'
def test_nil_best_match():
    nilaccept = NilAccept('Connection-Close')
    assert nilaccept.best_match(['foo', 'bar']) == 'foo'
    assert nilaccept.best_match([('foo', 1), ('bar', 0.5)]) == 'foo'
    assert nilaccept.best_match([('foo', 0.5), ('bar', 1)]) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar']) == 'bar'
    # default_match has no effect on NilAccept class
    assert nilaccept.best_match([('foo', 0.5), 'bar'],
                                default_match=True) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar'],
                                default_match=False) == 'bar'
Example #8
0
def test_nil_best_match():
    nilaccept = NilAccept()
    assert nilaccept.best_match(['foo', 'bar']) == 'foo'
    assert nilaccept.best_match([('foo', 1), ('bar', 0.5)]) == 'foo'
    assert nilaccept.best_match([('foo', 0.5), ('bar', 1)]) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar']) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar'],
                                default_match=True) == 'bar'
    assert nilaccept.best_match([('foo', 0.5), 'bar'],
                                default_match=False) == 'bar'
    assert nilaccept.best_match([], default_match='fallback') == 'fallback'
Example #9
0
def test_nil_radd_masterclass():
    # Is this "reaching into" __radd__ legit?
    nilaccept = NilAccept()
    accept = Accept('text/html')
    assert nilaccept.__radd__(accept) is accept
Example #10
0
def test_nil_radd():
    nilaccept = NilAccept()
    accept = Accept('text/html')
    assert isinstance('foo' + nilaccept, accept.__class__)
    assert ('foo' + nilaccept).header_value == 'foo'
def test_nil_first_match():
    nilaccept = NilAccept('Connection-Close')
    # NilAccept.first_match always returns element 0 of the list
    assert nilaccept.first_match(['dummy', '']) == 'dummy'
    assert nilaccept.first_match(['', 'dummy']) == ''
def test_nil_contains():
    nilaccept = NilAccept('Connection-Close')
    # NilAccept.__contains__ always returns True
    assert '' in nilaccept
    assert 'dummy' in nilaccept
def test_nil_radd():
    nilaccept = NilAccept('Connection-Close')
    accept = Accept('Content-Type', 'text/html')
    assert isinstance('foo' + nilaccept, accept.__class__)
    assert ('foo' + nilaccept).header_value == 'foo'
Example #14
0
def test_nil_radd_masterclass():
    # Is this "reaching into" __radd__ legit?
    nilaccept = NilAccept()
    accept = Accept('text/html')
    assert nilaccept.__radd__(accept) is accept
Example #15
0
def test_nil_contains():
    nilaccept = NilAccept()
    assert 'anything' in nilaccept
def test_nil_radd_masterclass():
    # Is this "reaching into" __radd__ legit?
    nilaccept = NilAccept('Connection-Close')
    accept = Accept('Content-Type', 'text/html')
    assert nilaccept.__radd__(accept) is accept
Example #17
0
 def NilAccept(self, *args, **kwargs):
     from webob.acceptparse import NilAccept
     return NilAccept(*args, **kwargs)