Exemplo n.º 1
0
def test_pair():
    t = ("a", "b")
    pair = Pair(t)
    assert pair == Pair(*t)
    assert pair == t
    assert pair == Pair("b", "a")
    assert pair == eval(repr(pair))
    assert str(pair) == "b - a"

    # Test unicode (C4 87 -> latin small letter C with acute)
    pair = Pair("a", "\xc4\x87")
    assert str(pair) == "\xc4\x87 - a"
Exemplo n.º 2
0
def test_pair():
    t = ('a', 'b')
    pair = Pair(t)
    assert_equal(pair, Pair(*t))
    assert_equal(pair, t)
    assert_equal(pair, Pair('b', 'a'))
    assert_equal(pair, eval(repr(pair)))
    assert_equal(str(pair), "b - a")

    # Test unicode (C4 87 -> latin small letter C with acute)
    pair = Pair("a", "\xc4\x87")
    assert_equal(str(pair), "\xc4\x87 - a")
Exemplo n.º 3
0
def test_pair():
    t = ('a', 'b')
    pair = Pair(t)
    assert_equal(pair, Pair(*t))
    assert_equal(pair, Pair('b', 'a'))
    assert_equal(pair, eval(repr(pair)))
    assert_equal(str(pair), "b - a")
    assert_equal(unicode(pair), u"b - a")

    # Non-ASCII characters should not cause exception if they're proper UTF-8
    pair = Pair("a", "\xc4\x87")
    str(pair)
    unicode(pair)
Exemplo n.º 4
0
def test_pair():
    # We cannot use six.u since it expects a string literal as argument and
    # we're passing an object.
    u = unicode if six.PY2 else str

    t = ('a', 'b')
    pair = Pair(t)
    assert_equal(pair, Pair(*t))
    assert_equal(pair, Pair('b', 'a'))
    assert_equal(pair, eval(repr(pair)))
    assert_equal(u(pair), "b - a")

    # Test unicode (C4 87 -> latin small letter C with acute)
    pair = Pair("a", "\xc4\x87")
    assert_equal(u(pair), "\xc4\x87 - a")
Exemplo n.º 5
0
def test_scoresheet():
    sheet = Scoresheet()
    t = ('a', 'b')
    sheet[t] = 5
    assert_equal(len(sheet), 1)
    assert_equal(sheet.items(), [(Pair('a', 'b'), 5.0)])
    assert_equal(sheet[t], 5.0)
    del sheet[t]
    assert_equal(len(sheet), 0)
Exemplo n.º 6
0
def test_scoresheet():
    sheet = Scoresheet()
    t = ("a", "b")
    sheet[t] = 5
    assert len(sheet) == 1
    assert list(sheet.items()) == [(Pair("a", "b"), 5.0)]
    assert sheet[t] == 5.0
    del sheet[t]
    assert len(sheet) == 0
Exemplo n.º 7
0
def test_pair_identical_elements():
    Pair('a', 'a')
Exemplo n.º 8
0
def test_pair_different_types():
    # Should not raise an error
    assert Pair("a", 1) == Pair(1, "a")
Exemplo n.º 9
0
def test_pair_identical_elements():
    with pytest.raises(AssertionError):
        Pair("a", "a")
Exemplo n.º 10
0
def test_pair_different_types():
    # Should not raise an error
    assert_equal(Pair('a', 1), Pair(1, 'a'))