Example #1
0
def test_verify_input1():
    """
    Test if input string is valid (not numeric)
    """

    text = 100

    with pytest.raises(TypeError) as e:
        text_quality(text)

    assert str(e.value) == "Input must be a string"
Example #2
0
def verify_input2():

    """
    Test if input is not empty
    """

    text = " "

    with pytest.raises(ValueError) as e:

        text_quality(text)

    assert str(e.value) == "Input must be a string"
Example #3
0
def test_output_type():
    """
    Test that output is of type DataFrame
    """
    text = "This str has words spelllll wrong. This string has a slag word shitty."
    output = text_quality(text)
    assert (type(output) == type(pd.DataFrame()))
Example #4
0
def test_output_type():

    """
    Test that output is of type DataFrame
    """

    assert(type(text_quality(text=x)) == type(pd.DataFrame()))
Example #5
0
def test_output_toxicity():

    """
    Test that toxicity gives expected output
    """

    output = text_quality(text=x)

    assert output.toxicity[0]>=0.06 and output.toxicity[0]<=0.09
Example #6
0
def test_output_spell_error():

    """
    Test that spell error gives expected output
    """

    output = text_quality(text=x)

    assert output.spell_error[0]>=0.14 and output.spell_error[0]<=0.16
Example #7
0
def test_verify_output1():
    """
    Test if input is not empty
    """
    text = "This str has words spelllll wrong. This string has a slag word shitty."
    output = text_quality(text)
    assert output['count_spell_error'][0] >= 0
    assert output['proportion_spell_error'][0] >= 0.0
    assert output['count_toxic_words'][0] >= 0
    assert output['proportion_toxic_words'][0] >= 0.0
Example #8
0
def test_output_float():

    """
    Test that output contains floats
    """

    output = text_quality(text=x)

    assert isinstance(output.spell_error[0], numpy.float64) | isinstance(output.spell_error[0], float)
    assert isinstance(output.toxicity[0], numpy.float64) | isinstance(output.spell_error[0], float)
Example #9
0
def test_output_positive():

    """
    Test that output contains non-negatives
    (since the spelling errors and toxicity by definition of
    this function cannot be negative)
    """

    output = text_quality(text=x)

    assert output.spell_error[0]>=0
    assert output.toxicity[0]>=0
Example #10
0
def test_verify_output2():
    """
    Test if input is not empty
    """
    text = "This string is correct."
    output = text_quality(text)

    assert output['spell_error'][0] == set()
    assert output['count_spell_error'][0] == 0
    assert output['proportion_spell_error'][0] == 0.0
    assert output['toxic_words'][0] == set()
    assert output['count_toxic_words'][0] == 0
    assert output['proportion_toxic_words'][0] == 0.0
Example #11
0
def test_output_types():
    """
    Test if input is not empty
    """

    text = "This str has words spelllll wrong. This string has a slag word shitty."
    output = text_quality(text)
    assert type(output['spell_error'][0]) == type(set())
    assert type(output['count_spell_error'][0]) == numpy.int64
    assert type(output['proportion_spell_error'][0]) == numpy.float64
    assert type(output['toxic_words'][0]) == type(set())
    assert type(output['count_toxic_words'][0]) == numpy.int64
    assert type(output['proportion_toxic_words'][0]) == numpy.float64
Example #12
0
def test_verify_output5():
    """
    Test if input is not empty
    """
    text = "this is Jim and Alex writing a package."
    output = text_quality(text)

    assert output['spell_error'][0] == set()
    assert output['count_spell_error'][0] == 0
    assert output['proportion_spell_error'][0] == 0.0
    assert output['toxic_words'][0] == set()
    assert output['count_toxic_words'][0] == 0
    assert output['proportion_toxic_words'][0] == 0.0
Example #13
0
def test_verify_output4():
    """
    Test if input is not empty
    """
    text = "This string has words spelllll wrong. This string has a slag word shitty."
    output = text_quality(text)

    assert output['spell_error'][0] == {'spelllll'}
    assert output['count_spell_error'][0] == 1
    assert ((output['proportion_spell_error'][0] >= 0.076923 - 0.2)
            and (output['proportion_spell_error'][0] <= 0.076923 + 0.2))
    assert output['toxic_words'][0] == {'shitty'}
    assert output['count_toxic_words'][0] == 1
    assert ((output['proportion_toxic_words'][0] >= 0.076923 - 0.2)
            and (output['proportion_toxic_words'][0] <= 0.076923 + 0.2))
Example #14
0
        text_quality(text)

    assert str(e.value) == "Input must be a string"


def verify_input3():

     """
     Test if input string is valid (not special characters)
     """

    text = "!#$*()&^%$#@!{}{{{}}}"

    with pytest.raises(ValueError) as e:

        text_quality(text)

    assert str(e.value) == "Input has no text"



def test_output_spell_error():

    """
    Test that spell error gives expected output
    """

    output = text_quality(text=x)

    assert output.spell_error[0]>=0.14 and output.spell_error[0]<=0.16