[Chennaipy] ChennaiPy - Monday Module - 30 May 2022

selvi dct selvi.dct at gmail.com
Mon May 30 10:52:53 EDT 2022


*Note: We have started a new series sharing a module, weekly once. Please
share your feedback. -- ChennaiPy*



*Module*: pynguin


*Installation*: pip install pynguin


*About*:

Pynguin, the PYthoN General UnIt test geNerator, is a tool that allows
developers to generate unit tests automatically.


Sample Source Code:

def triangle(x: int, y: int, z: int) -> str:

    if x == y == z:

return "Equilateral triangle"

    elif x == y or y == z or x == z:

return "Isosceles triangle"

    else:

return "Scalene triangle"


*Prerequisite*:

To help prevent harming the system that runs Pynguin, its CLI will
immediately abort unless the environment variable PYNGUIN_DANGER_AWARE is
set.

ChennaiPy $ export PYNGUIN_DANGER_AWARE=1


*Execution*:

ChennaiPy $ pynguin --project_path ./ --output-path pynguin_output
--module-name pynguin_demo

ChennaiPy $ cd pynguin_output

pynguin_output $ ls -rtl

total 16

-rw-r--r--  1 dev  staff  879 29 May 23:26 test_pynguin_demo.py

-rw-r--r--  1 dev  staff   38 29 May 23:26 test_pynguin_demo_failing.py



Output:

*### Below testcases are automatically created by the module, with
different values passed*

# Automatically generated by Pynguin.

import pynguin_demo as module_0



def test_case_0():

    int_0 = -156

    int_1 = -5206

    str_0 = module_0.triangle(int_1, int_0, int_1)

    assert str_0 == 'Isosceles triangle'

    str_1 = module_0.triangle(int_0, int_0, int_0)

    assert str_1 == 'Equilateral triangle'



def test_case_1():

    int_0 = 1038

    int_1 = 5772

    str_0 = module_0.triangle(int_0, int_1, int_1)

    assert str_0 == 'Isosceles triangle'



def test_case_2():

    int_0 = -785

    int_1 = 3730

    int_2 = -1030

    str_0 = module_0.triangle(int_1, int_1, int_2)

    assert str_0 == 'Isosceles triangle'

    str_1 = module_0.triangle(int_0, int_0, int_0)

    assert str_1 == 'Equilateral triangle'



def test_case_3():

    int_0 = 1910

    int_1 = 899

    int_2 = None

    str_0 = module_0.triangle(int_0, int_1, int_2)

    assert str_0 == 'Scalene triangle'


*Reference*: https://pynguin.readthedocs.io/en/latest/user/quickstart.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/chennaipy/attachments/20220530/882210fb/attachment-0001.html>


More information about the Chennaipy mailing list