示例#1
0
def test_rfc1459():
    """Test rfc1459 casemap"""
    str1 = String("ABC|{", RFC1459)
    str2 = String("abc\\[", RFC1459)

    assert str1 == str2
    assert str(str1.lower()) == str(str2.lower())
    assert str(str1.upper()) == str(str2.upper())
示例#2
0
def test_startswith():
    """Test `startswith`"""
    s = String("aBc")
    assert s.startswith("a")
    assert s.startswith("ab")
    assert s.startswith(String("aB"))
    assert s.startswith(("a", "b"))
示例#3
0
def test_endswith():
    """Test `endswith`"""
    s = String("aBc")
    assert s.endswith("c")
    assert s.endswith("bC")
    assert s.endswith(String("bc"))
    assert s.endswith(("b", "c"))
示例#4
0
def test_rindex():
    """Test `rindex`"""
    s = String("AbCB")
    assert s.rindex("B") == 3
    assert s.rindex(String("B")) == 3
    with pytest.raises(ValueError):
        s.rindex("d")
示例#5
0
def test_index():
    """Test `index`"""
    s = String("AbCB")
    assert s.index("B") == 1
    assert s.index(String("B")) == 1
    with pytest.raises(ValueError):
        s.index("d")
示例#6
0
def test_strip():
    """Test stripping characters"""
    s = String("AbCbAcBa")
    assert s.strip("d") == "AbCbAcBa"
    assert s.strip("a") == "bCbAcB"
    s1 = String(" ABc  ")
    assert s1.strip() == "ABc"
示例#7
0
def test_comparisons():
    """Test comparison logic"""
    # pylint: disable=misplaced-comparison-constant, unneeded-not
    str1 = String("A", ASCII)
    str1_ = str1
    str2 = String("a", ASCII)

    assert str1.casemap is ASCII
    assert str2.casemap is ASCII

    assert str1 == "A"
    assert str2 == "a"

    assert str(str1.lower()) == "a"
    assert str(str2.lower()) == "a"

    assert str(str1.upper()) == "A"
    assert str(str2.upper()) == "A"

    assert str1 == str1_
    assert str1 == str2

    assert str1 == "a"
    assert "a" == str1

    assert str2 == "a"
    assert "a" == str2

    assert str1 == "A"
    assert "A" == str1

    assert str2 == "A"
    assert "A" == str2

    assert not str1 > str2
    assert not str1 > "a"

    assert "B" > str2
    assert not str2 > "B"
    assert str2 < "B"
    assert not "B" < str2
    assert not str2 >= "B"
    assert str2 <= "B"
    assert "B" >= str2
    assert not "B" <= str2

    assert str2 != "B"
示例#8
0
def test_msg_split(data):
    """Test splitting a message against the irc-parser-tests data"""
    msg = Message.parse(data["input"])
    atoms = data["atoms"].copy()

    # We store tags a bit differently than the test data expects, convert the format
    if msg.tags is not None:
        tags_dict = {name: tag.value for name, tag in msg.tags.items()}
    else:
        tags_dict = None

    assert tags_dict == atoms.pop("tags", None)

    prefix = None if msg.prefix is None else str(msg.prefix)
    assert prefix == atoms.pop("source", None)

    # Commands are case-insensitive
    assert String(msg.command, ASCII) == atoms.pop("verb", None)

    assert list(msg.parameters) == atoms.pop("params", [])

    # Make sure we handled everything
    assert not atoms
示例#9
0
def test_rfind():
    """Test `rfind`"""
    s = String("AbCB")
    assert s.rfind("B") == 3
    assert s.rfind(String("B")) == 3
    assert s.rfind("d") == -1
示例#10
0
def test_count():
    """Test `count`"""
    assert String("aabbcc").count("a") == 2
    assert String("aabbcc").count(String("a")) == 2
示例#11
0
def test_find():
    """Test `find`"""
    s = String("AbCB")
    assert s.find("B") == 1
    assert s.find(String("B")) == 1
    assert s.find("d") == -1
示例#12
0
def test_swapcase():
    """Test `swapcase`"""
    s = String("abC")
    assert s.swapcase() == "ABc"
示例#13
0
def test_hash():
    """Test hashing a string"""
    assert hash(String("ABC")) == hash(String("abc"))
示例#14
0
def test_capitalize():
    """Test `capitalize`"""
    s = String("abC")
    assert s.capitalize() == "Abc"
示例#15
0
def test_contains():
    """Test `in` operator"""
    assert "a" in String("abc")
    assert String("a") in String("abc")
示例#16
0
def test_getitem():
    """Test `getitem`"""
    s = String("abc")
    assert s[0] == "a"
    assert isinstance(s[0], String)
    assert s[0].casemap is s.casemap
示例#17
0
def test_partition():
    """Test partition"""
    s = String("ABc")
    assert s.partition("b") == ("A", "B", "c")
    assert s.partition("d") == ("ABc", "", "")
示例#18
0
def test_rpartition():
    """Test rpartition"""
    s = String("AbCbAcBa")
    assert s.rpartition("b") == ("AbCbAc", "B", "a")
    assert s.rpartition("d") == ("", "", "AbCbAcBa")