Exemplo n.º 1
0
def test_listReplace():
    """Ensure replacing a list of items from a string works correctly"""
    myString = "A string of text"
    assert StringUtils.listReplace(myString, ['A', 'text', 'string'],
                                   "AHH") == "AHH AHH of AHH"
    assert StringUtils.listReplace(myString, ['A', 'text', 'string'],
                                   ["1", "2", "3"]) == "1 3 of 2"
Exemplo n.º 2
0
def test_generateRandomKey():
    randomKey1 = StringUtils.generateRandomKey()
    randomKey2 = StringUtils.generateRandomKey()
    assert randomKey1 != randomKey2
    assert len(randomKey1) == len(randomKey2) == 20

    randomKey1 = StringUtils.generateRandomKey(40)
    randomKey2 = StringUtils.generateRandomKey(40)
    assert randomKey1 != randomKey2
    assert len(randomKey1) == len(randomKey2) == 40
Exemplo n.º 3
0
def test_generateRandomKey():
    randomKey1 = StringUtils.generateRandomKey()
    randomKey2 = StringUtils.generateRandomKey()
    assert randomKey1 != randomKey2
    assert len(randomKey1) == len(randomKey2) == 20

    randomKey1 = StringUtils.generateRandomKey(40)
    randomKey2 = StringUtils.generateRandomKey(40)
    assert randomKey1 != randomKey2
    assert len(randomKey1) == len(randomKey2) == 40
Exemplo n.º 4
0
def test_stripControlChars():
    """Ensure we properly remove control characters (not including \r\n\t"""
    controlCharText = ''.join(StringUtils.INVALID_CONTROL_CHARACTERS) + \
                      "THE STRING" + ''.join(StringUtils.INVALID_CONTROL_CHARACTERS)
    assert StringUtils.stripControlChars(controlCharText) == "THE STRING"
    assert StringUtils.stripControlChars(controlCharText, fromFront=False) == \
              ''.join(StringUtils.INVALID_CONTROL_CHARACTERS) + "THE STRING"
    assert StringUtils.stripControlChars(controlCharText, fromBack=False) == \
              "THE STRING" + ''.join(StringUtils.INVALID_CONTROL_CHARACTERS)
    assert StringUtils.stripControlChars(controlCharText, fromFront=False, fromBack=False) == \
              ''.join(StringUtils.INVALID_CONTROL_CHARACTERS) + "THE STRING" + \
              ''.join(StringUtils.INVALID_CONTROL_CHARACTERS)
Exemplo n.º 5
0
def test_stripControlChars():
    """Ensure we properly remove control characters (not including \r\n\t"""
    controlCharText = ''.join(StringUtils.INVALID_CONTROL_CHARACTERS) + \
                      "THE STRING" + ''.join(StringUtils.INVALID_CONTROL_CHARACTERS)
    assert StringUtils.stripControlChars(controlCharText) == "THE STRING"
    assert StringUtils.stripControlChars(controlCharText, fromFront=False) == \
              ''.join(StringUtils.INVALID_CONTROL_CHARACTERS) + "THE STRING"
    assert StringUtils.stripControlChars(controlCharText, fromBack=False) == \
              "THE STRING" + ''.join(StringUtils.INVALID_CONTROL_CHARACTERS)
    assert StringUtils.stripControlChars(controlCharText, fromFront=False, fromBack=False) == \
              ''.join(StringUtils.INVALID_CONTROL_CHARACTERS) + "THE STRING" + \
              ''.join(StringUtils.INVALID_CONTROL_CHARACTERS)
Exemplo n.º 6
0
def test_interpretAsString():
    """Ensure the interpret as string utility function correctly takes objects and turns them into
       strings
    """
    testList = ['1a', '2b', '3c', '4d']
    assert StringUtils.interpretAsString(testList) == "1a 2b 3c 4d"

    testTuple = ('1a', '2b', '3c', '4d')
    assert StringUtils.interpretAsString(testTuple) == "1a 2b 3c 4d"

    testDictionary = {1:'a', 2:'b', 3:'c', 4:'d'}
    assert StringUtils.interpretAsString(testDictionary) == "1:a;2:b;3:c;4:d;"

    testBoolean = True
    assert StringUtils.interpretAsString(testBoolean) == "true"

    testBoolean = False
    assert StringUtils.interpretAsString(testBoolean) == "false"

    testFloat = 1.0 / 4.0
    assert StringUtils.interpretAsString(testFloat) == "25.000000%"

    def testFunction():
        return "hello"
    assert StringUtils.interpretAsString(testFunction) == "hello"

    assert StringUtils.interpretAsString("") == u""
Exemplo n.º 7
0
def test_interpretFromString():
    """Ensure the interpret from string utility method correctly takes strings and turns them into
       objects
    """
    assert StringUtils.interpretFromString("True") == True
    assert StringUtils.interpretFromString("trUE") == True

    assert StringUtils.interpretFromString("False") == False
    assert StringUtils.interpretFromString("fAlSe") == False

    assert StringUtils.interpretFromString("None") == None
    assert StringUtils.interpretFromString("NOnE") == None

    assert StringUtils.interpretFromString("Some other value") == "Some other value"
Exemplo n.º 8
0
def test_interpretFromString():
    """Ensure the interpret from string utility method correctly takes strings and turns them into
       objects
    """
    assert StringUtils.interpretFromString("True") == True
    assert StringUtils.interpretFromString("trUE") == True

    assert StringUtils.interpretFromString("False") == False
    assert StringUtils.interpretFromString("fAlSe") == False

    assert StringUtils.interpretFromString("None") == None
    assert StringUtils.interpretFromString("NOnE") == None

    assert StringUtils.interpretFromString(
        "Some other value") == "Some other value"
Exemplo n.º 9
0
def test_findIndexes():
    string = "There is an A here and an A here there is an A everywhere"
    assert StringUtils.findIndexes(string, "A") == set((12, 26, 45))
    assert StringUtils.findIndexes(string, "is an") == set((6, 39))
    assert StringUtils.findIndexes(string, "monkey") == set()
Exemplo n.º 10
0
def test_removeDelimiters():
    """Ensure removing delimeters works correctly"""
    string = "Th.is, shou+ld wo-rk /I thi\\nk"
    assert StringUtils.removeDelimiters(string) == "This should work I think"
    assert StringUtils.removeDelimiters(
        string, replacement=" ") == "Th is  shou ld wo rk  I thi nk"
Exemplo n.º 11
0
def test_removeAlphas():
    """ Ensure that the utility function to remove alpha characters works successfully """
    assert StringUtils.removeAlphas(
        'afjsafdl121323213adfas1231321') == "1213232131231321"
    assert StringUtils.removeAlphas('213123123123231') == "213123123123231"
Exemplo n.º 12
0
def test_findIndexes():
    string = "There is an A here and an A here there is an A everywhere"
    assert StringUtils.findIndexes(string, "A") == set((12, 26, 45))
    assert StringUtils.findIndexes(string, "is an") == set((6, 39))
    assert StringUtils.findIndexes(string, "monkey") == set()
Exemplo n.º 13
0
def test_removeDelimiters():
    """Ensure removing delimeters works correctly"""
    string = "Th.is, shou+ld wo-rk /I thi\\nk"
    assert StringUtils.removeDelimiters(string) == "This should work I think"
    assert StringUtils.removeDelimiters(string, replacement=" ") == "Th is  shou ld wo rk  I thi nk"
Exemplo n.º 14
0
def test_listReplace():
    """Ensure replacing a list of items from a string works correctly"""
    myString = "A string of text"
    assert StringUtils.listReplace(myString, ['A', 'text', 'string'], "AHH") == "AHH AHH of AHH"
    assert StringUtils.listReplace(myString, ['A', 'text', 'string'], ["1", "2", "3"]) == "1 3 of 2"
Exemplo n.º 15
0
def test_removeAlphas():
    """ Ensure that the utility function to remove alpha characters works successfully """
    assert StringUtils.removeAlphas('afjsafdl121323213adfas1231321') == "1213232131231321"
    assert StringUtils.removeAlphas('213123123123231') == "213123123123231"