예제 #1
0
def enumName():
    # arrange
    @Enum(associateReturnsTo='value', instanceLog=False)
    class MyOtherEnumTest:
        ONE = EnumItem(value=1, otherValue='1')
        TWO = EnumItem(value=2, otherValue='1')
        THREE = EnumItem(value=3, otherValue='1')

    @Enum(associateReturnsTo='value', instanceLog=False)
    class MyThirdEnumTest:
        ONE = EnumItem(value=4, otherValue='1')
        TWO = EnumItem(value=5, otherValue='1')
        THREE = EnumItem(value=6, otherValue='1')

    ITS_NAME = RandomHelper.string(minimum=5, maximum=10)
    A_NAME = RandomHelper.string(minimum=5, maximum=10)
    TEST_NAME = RandomHelper.string(minimum=5, maximum=10)
    ITS_LABEL = RandomHelper.string(minimum=5, maximum=10)
    A_LABEL = RandomHelper.string(minimum=5, maximum=10)
    TEST_LABEL = RandomHelper.string(minimum=5, maximum=10)
    ITS_NUMERIC = RandomHelper.integer(minimum=5, maximum=1000)
    A_NUMERIC = RandomHelper.integer(minimum=5, maximum=1000)
    TEST_NUMERIC = RandomHelper.integer(minimum=5, maximum=1000)
    ITS_VALUE = 'ITS'
    A_VALUE = 'A'
    TEST_VALUE = 'TEST'

    @Enum()
    class MyEnumTest:
        ITS = EnumItem(name=ITS_NAME, label=ITS_LABEL, numeric=ITS_NUMERIC)
        A = EnumItem(name=A_NAME, label=A_LABEL, numeric=A_NUMERIC)
        TEST = EnumItem(name=TEST_NAME, label=TEST_LABEL, numeric=TEST_NUMERIC)

    MY_ENUM_TEST = MyEnumTest()

    # act
    enumType = MY_ENUM_TEST

    # assert
    assert 'OK' == HttpStatus.OK.enumName
    assert 'ONE' == MyOtherEnumTest().ONE.enumName
    assert 'ONE' == MyOtherEnumTest.ONE.enumName
    assert 1 == MyOtherEnumTest.ONE
    assert MyEnumTest.map(MY_ENUM_TEST.ITS.enumValue) == MY_ENUM_TEST.ITS
    assert MyEnumTest.map(MY_ENUM_TEST.ITS) == MY_ENUM_TEST.ITS
    assert MyOtherEnumTest.map(
        MyOtherEnumTest.ONE.enumValue) == MyOtherEnumTest.ONE
    assert MyOtherEnumTest.map(MyOtherEnumTest.ONE) == MyOtherEnumTest.ONE
    assert MyOtherEnumTest.map('ONE') == MyOtherEnumTest.ONE.enumValue
    assert MyOtherEnumTest.map('ONE') == MyOtherEnumTest.ONE
    assert MY_ENUM_TEST.map('TEST') == MyEnumTest.TEST.enumValue
    assert MY_ENUM_TEST.map('TEST') == MyEnumTest.TEST
    assert MyEnumTest == type(enumType)
def convertFromObjectToObject_whenTargetClassIsList() :
    # arrange
    a = RandomHelper.string()
    b = RandomHelper.string()
    c = RandomHelper.string()
    otherA = MyOtherDto(RandomHelper.string())
    otherB = MyOtherDto(RandomHelper.string())
    otherC = MyOtherDto(RandomHelper.string())
    myFirst = MyDto(RandomHelper.string(), otherA, [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), None), RandomHelper.integer())]), RandomHelper.integer())]), RandomHelper.integer())]), RandomHelper.integer())])
    mySecond = MyDto(RandomHelper.string(), otherB, [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), None), RandomHelper.integer())]), RandomHelper.integer())]), RandomHelper.integer())]), RandomHelper.integer())])
    myThird = MyDto(RandomHelper.string(), otherC, [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), [MyThirdDto(MyDto(RandomHelper.string(), MyOtherDto(RandomHelper.string()), None), RandomHelper.integer())]), RandomHelper.integer())]), RandomHelper.integer())]), RandomHelper.integer())])
    thirdOne = RandomHelper.integer()
    thirdTwo = RandomHelper.integer()
    thirdThree = RandomHelper.integer()
    myThirdOne = [MyThirdDto(myFirst, thirdOne)]
    myThirdTwo = [MyThirdDto(mySecond, thirdTwo)]
    myThirdThree = [MyThirdDto(myThird, thirdThree)]
    expected = [MyDto(a, otherA, myThirdOne), MyDto(b, otherB, myThirdTwo), MyDto(c, otherC, myThirdThree)]
    null = 'null'
    inspectEquals = False

    # act
    toAssert = Serializer.convertFromObjectToObject(expected, [[MyDto]])
    another = Serializer.convertFromObjectToObject([MyDto(a, otherA, [MyThirdDto(myFirst, thirdOne)]), MyDto(b, otherB, myThirdTwo), MyDto(c, otherC, myThirdThree)], [[MyDto]])
    another[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my = MyDto(
        MyDto(RandomHelper.string(), None, None),
        expected[0].myThirdList[0].my.myOther,
        expected[0].myThirdList[0].my.myThirdList
    )

    # assert
    assert expected == toAssert, f'{expected} == {toAssert}: {expected == toAssert}'
    assert ObjectHelper.equals(expected, toAssert)
    assert ObjectHelper.isNotNone(expected[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my)
    assert expected[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my == toAssert[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my
    assert ObjectHelper.equals(expected[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my, toAssert[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my)
    assert ObjectHelper.isNone(expected[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList)
    assert ObjectHelper.equals(expected[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList, toAssert[0].myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList[0].my.myThirdList)
    assert ObjectHelper.equals(json.loads(Serializer.jsonifyIt(expected)), json.loads(Serializer.jsonifyIt(toAssert))), f'ObjectHelper.equals({json.loads(Serializer.jsonifyIt(expected))},\n\n{json.loads(Serializer.jsonifyIt(toAssert))})'
    assert False == (expected == another), f'False == ({expected} == {another}): False == {(expected == another)}'
    assert False == ObjectHelper.equals(expected, another, muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(another, expected, muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(another, toAssert, muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(toAssert, another, muteLogs=not inspectEquals)
    assert str(expected) == str(toAssert), f'str({str(expected)}) == str({str(toAssert)}): {str(expected) == str(toAssert)}'
def randomValues():
    # Arrange
    MINIMUM_CUSTOM_RANGE = 30
    MAXIMUM_CUSTOM_RANGE = 10
    OTHER_MINIMUM_CUSTOM_RANGE = 100
    OTHER_MAXIMUM_CUSTOM_RANGE = 200
    MINIMUM_CUSTOM_FLOAT_RANGE = 400.33
    MAXIMUM_CUSTOM_FLOAT_RANGE = 500.55

    # Act
    stringValueInDefaultRange = RandomHelper.string()
    stringValueInCustomRange = RandomHelper.string(
        minimum=MINIMUM_CUSTOM_RANGE, maximum=MAXIMUM_CUSTOM_RANGE)
    stringValueInOtherCustomRange = RandomHelper.string(
        minimum=OTHER_MINIMUM_CUSTOM_RANGE, maximum=OTHER_MAXIMUM_CUSTOM_RANGE)
    integerValueInDefaultRange = RandomHelper.integer()
    integerValueInCustomRange = RandomHelper.integer(
        minimum=MINIMUM_CUSTOM_RANGE, maximum=MAXIMUM_CUSTOM_RANGE)
    integerValueInOtherCustomRange = RandomHelper.integer(
        minimum=OTHER_MINIMUM_CUSTOM_RANGE, maximum=OTHER_MAXIMUM_CUSTOM_RANGE)
    floatValueInDefaultRange = RandomHelper.float()
    floatValueInCustomRange = RandomHelper.float(minimum=MINIMUM_CUSTOM_RANGE,
                                                 maximum=MAXIMUM_CUSTOM_RANGE)
    floatValueInOtherCustomRange = RandomHelper.float(
        minimum=OTHER_MINIMUM_CUSTOM_RANGE, maximum=OTHER_MAXIMUM_CUSTOM_RANGE)
    floatValueInOtherCustomFloatRange = RandomHelper.float(
        minimum=MINIMUM_CUSTOM_FLOAT_RANGE, maximum=MAXIMUM_CUSTOM_FLOAT_RANGE)

    # Assert
    assert RandomHelper.DEFAULT_MINIMUM_LENGHT <= len(
        stringValueInDefaultRange) <= RandomHelper.DEFAULT_MAXIMUM_LENGHT
    assert MINIMUM_CUSTOM_RANGE == len(stringValueInCustomRange)
    assert OTHER_MINIMUM_CUSTOM_RANGE <= len(
        stringValueInOtherCustomRange) <= OTHER_MAXIMUM_CUSTOM_RANGE
    assert RandomHelper.DEFAULT_MINIMUM_LENGHT <= integerValueInDefaultRange <= RandomHelper.DEFAULT_MAXIMUM_LENGHT
    assert MINIMUM_CUSTOM_RANGE == integerValueInCustomRange
    assert OTHER_MINIMUM_CUSTOM_RANGE <= integerValueInOtherCustomRange <= OTHER_MAXIMUM_CUSTOM_RANGE
    assert RandomHelper.DEFAULT_MINIMUM_LENGHT <= floatValueInDefaultRange <= RandomHelper.DEFAULT_MAXIMUM_LENGHT
    assert MINIMUM_CUSTOM_RANGE == floatValueInCustomRange
    assert OTHER_MINIMUM_CUSTOM_RANGE <= floatValueInOtherCustomRange < OTHER_MAXIMUM_CUSTOM_RANGE
    assert MINIMUM_CUSTOM_FLOAT_RANGE <= floatValueInOtherCustomFloatRange <= MAXIMUM_CUSTOM_FLOAT_RANGE
예제 #4
0
def enum_withSuccess():
    TEST_ITERATION = 1
    ASSERT_ITERATION = 1
    discount = 0
    instanciationTime = 0
    equalTestTime = 0
    start = time.time()
    for _ in range(TEST_ITERATION):
        # arrange
        discountStart = time.time()
        ITS_NAME = RandomHelper.string(minimum=5, maximum=10)
        A_NAME = RandomHelper.string(minimum=5, maximum=10)
        TEST_NAME = RandomHelper.string(minimum=5, maximum=10)
        ITS_LABEL = RandomHelper.string(minimum=5, maximum=10)
        A_LABEL = RandomHelper.string(minimum=5, maximum=10)
        TEST_LABEL = RandomHelper.string(minimum=5, maximum=10)
        ITS_NUMERIC = RandomHelper.integer(minimum=5, maximum=1000)
        A_NUMERIC = RandomHelper.integer(minimum=5, maximum=1000)
        TEST_NUMERIC = RandomHelper.integer(minimum=5, maximum=1000)
        ITS_VALUE = 'ITS'
        A_VALUE = 'A'
        TEST_VALUE = 'TEST'
        discount += time.time() - discountStart

        # act
        discountStart = time.time()

        @Enum()
        class MyEnumTest:
            ITS = EnumItem(name=ITS_NAME, label=ITS_LABEL, numeric=ITS_NUMERIC)
            A = EnumItem(name=A_NAME, label=A_LABEL, numeric=A_NUMERIC)
            TEST = EnumItem(name=TEST_NAME,
                            label=TEST_LABEL,
                            numeric=TEST_NUMERIC)

        discount += time.time() - discountStart
        instanciationTimeInit = time.time()
        MY_ENUM_TEST = MyEnumTest()
        instanciationTime += time.time() - instanciationTimeInit

        # assert
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert ITS_VALUE == MY_ENUM_TEST.ITS
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'ITS_VALUE == MY_ENUM_TEST.ITS assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert A_VALUE == MY_ENUM_TEST.A
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'A_VALUE == MY_ENUM_TEST.A assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert TEST_VALUE == MY_ENUM_TEST.TEST
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'TEST_VALUE == MY_ENUM_TEST.TEST assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert ITS_NAME == MY_ENUM_TEST.ITS.name
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'ITS_NAME == MY_ENUM_TEST.ITS.name assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert A_NAME == MY_ENUM_TEST.A.name
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'A_NAME == MY_ENUM_TEST.A.name assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert TEST_NAME == MY_ENUM_TEST.TEST.name
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'TEST_NAME == MY_ENUM_TEST.TEST.name assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert ITS_LABEL == MY_ENUM_TEST.ITS.label
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'ITS_LABEL == MY_ENUM_TEST.ITS.label assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert A_LABEL == MY_ENUM_TEST.A.label
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'A_LABEL == MY_ENUM_TEST.A.label assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert TEST_LABEL == MY_ENUM_TEST.TEST.label
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'TEST_LABEL == MY_ENUM_TEST.TEST.label assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert ITS_NUMERIC == MY_ENUM_TEST.ITS.numeric
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'ITS_NUMERIC == MY_ENUM_TEST.ITS.numeric assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert A_NUMERIC == MY_ENUM_TEST.A.numeric
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'A_NUMERIC == MY_ENUM_TEST.A.numeric assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert TEST_NUMERIC == MY_ENUM_TEST.TEST.numeric
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'TEST_NUMERIC == MY_ENUM_TEST.TEST.numeric assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MyEnumTest.map(
                MY_ENUM_TEST.ITS.enumValue) == MY_ENUM_TEST.ITS
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MyEnumTest.map(MY_ENUM_TEST.ITS.enumValue) == MY_ENUM_TEST.ITS assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MyEnumTest.map(MY_ENUM_TEST.A.enumValue) == MY_ENUM_TEST.A
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MyEnumTest.map(MY_ENUM_TEST.A.enumValue) == MY_ENUM_TEST.A assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MyEnumTest.map(
                MY_ENUM_TEST.TEST.enumValue) == MY_ENUM_TEST.TEST
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MyEnumTest.map(MY_ENUM_TEST.TEST.enumValue) == MY_ENUM_TEST.TEST assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MY_ENUM_TEST.ITS.enumValue.enum == MY_ENUM_TEST
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MY_ENUM_TEST.ITS.enumValue.enum == MY_ENUM_TEST assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MY_ENUM_TEST.A.enumValue.enum == MY_ENUM_TEST
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MY_ENUM_TEST.A.enumValue.enum == MY_ENUM_TEST assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MY_ENUM_TEST.TEST.enumValue.enum == MY_ENUM_TEST
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MY_ENUM_TEST.TEST.enumValue.enum == MY_ENUM_TEST assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert not MY_ENUM_TEST.ITS.enumValue.enum == MyEnumTest
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'not MY_ENUM_TEST.ITS.enumValue.enum == MyEnumTest assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert not MY_ENUM_TEST.A.enumValue.enum == MyEnumTest
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'not MY_ENUM_TEST.A.enumValue.enum == MyEnumTest assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert not MY_ENUM_TEST.TEST.enumValue.enum == MyEnumTest
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'not MY_ENUM_TEST.TEST.enumValue.enum == MyEnumTest assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        equalTestTimeStart = time.time()
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MY_ENUM_TEST.ITS.enumValue.enum == MyEnumTest()
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MY_ENUM_TEST.ITS.enumValue.enum == MyEnumTest() assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MY_ENUM_TEST.A.enumValue.enum == MyEnumTest()
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MY_ENUM_TEST.A.enumValue.enum == MyEnumTest() assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        timeAssertInit = time.time()
        for _ in range(ASSERT_ITERATION):
            assert MY_ENUM_TEST.TEST.enumValue.enum == MyEnumTest()
        discountStart = time.time()
        log.log(
            enum_withSuccess,
            f'MY_ENUM_TEST.TEST.enumValue.enum == MyEnumTest() assert duration: {time.time() - timeAssertInit}'
        )
        discount += time.time() - discountStart
        assert MyEnumTest() == MyEnumTest()
        equalTestTime += (time.time() - equalTestTimeStart)
예제 #5
0
import importlib

importlib.invalidate_caches()
from python_helper import EnvironmentHelper, log, RandomHelper

EnvironmentHelper.update("URL_VARIANT",
                         RandomHelper.integer(minimum=0, maximum=10000))
log.debug(log.debug, f'variant: {EnvironmentHelper.get("URL_VARIANT")}')

from python_helper import TestHelper

TestHelper.run(__file__)
# TestHelper.run(
#     __file__,
#     runOnly = [
#         'TestApiTest.testing_Client'
#     ]
# )
# TestHelper.run(
#     __file__,
#     runOnly = [
#         'EnumAnnotationTest.enum_withSuccess',
#         'EnumAnnotationTest.otherEnum_withSuccess',
#         'EnumAnnotationTest.python_framework_status',
#         'EnumAnnotationTest.enumName',
#         'EnumAnnotationTest.enumName_badImplementation',
#         'EnumAnnotationTest.map_whenArgIsNone',
#         'EnumAnnotationTest.Enum_whenHaveMoreThanOneInnerValue',
#         'EnumAnnotationTest.Enum_dot_map',
#         'EnumAnnotationTest.Enum_str',
#         'EnumAnnotationTest.Enum_strInOutput'
예제 #6
0
def equal_whenObjects():
    # arrange
    a = RandomHelper.string()
    b = RandomHelper.string()
    c = RandomHelper.string()
    otherA = MyOtherDto(RandomHelper.string())
    otherB = MyOtherDto(RandomHelper.string())
    otherC = MyOtherDto(RandomHelper.string())
    myFirst = MyDto(None, None, None)
    mySecond = MyDto(None, None, None)
    myThird = MyDto(None, None, None)
    thirdOne = RandomHelper.integer()
    thirdTwo = RandomHelper.integer()
    thirdThree = RandomHelper.integer()
    myThirdOne = [MyThirdDto(myFirst, thirdOne)]
    myThirdTwo = [MyThirdDto(mySecond, thirdTwo)]
    myThirdThree = [MyThirdDto(myThird, thirdThree)]
    expected = [
        MyDto(a, otherA, myThirdOne),
        MyDto(b, otherB, myThirdTwo),
        MyDto(c, otherC, myThirdThree)
    ]
    null = 'null'
    inspectEquals = False

    # act
    toAssert = [
        MyDto(a, otherA, myThirdOne),
        MyDto(b, otherB, myThirdTwo),
        MyDto(c, otherC, myThirdThree)
    ]
    another = [
        MyDto(a, otherA, [MyThirdDto(myFirst, thirdOne)]),
        MyDto(b, otherB, myThirdTwo),
        MyDto(c, otherC, myThirdThree)
    ]
    another[0].myThirdList[0].my = MyDto(
        MyDto(None, None, None), expected[0].myThirdList[0].my.myOther,
        expected[0].myThirdList[0].my.myThirdList)

    # assert
    assert False == (
        expected == toAssert
    ), f'False == ({expected} == {toAssert}): {False == (expected == toAssert)}'
    assert ObjectHelper.equals(expected, toAssert)
    assert ObjectHelper.equals(toAssert, expected)
    assert ObjectHelper.isNotNone(
        expected[0].myThirdList[0].my), expected[0].myThirdList[0].my
    assert expected[0].myThirdList[0].my == toAssert[0].myThirdList[0].my
    assert ObjectHelper.equals(expected[0].myThirdList[0].my,
                               toAssert[0].myThirdList[0].my)
    assert ObjectHelper.isNone(expected[0].myThirdList[0].my.myThirdList)
    assert ObjectHelper.equals(expected[0].myThirdList[0].my.myThirdList,
                               toAssert[0].myThirdList[0].my.myThirdList)
    assert ObjectHelper.equals(expected[1].myThirdList[0],
                               toAssert[1].myThirdList[0])
    assert ObjectHelper.equals(toAssert[1].myThirdList[0],
                               expected[1].myThirdList[0])
    assert False == (
        expected == another
    ), f'False == ({expected} == {another}): False == {(expected == another)}'
    assert False == ObjectHelper.equals(expected,
                                        another,
                                        muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(another,
                                        expected,
                                        muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(another,
                                        toAssert,
                                        muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(toAssert,
                                        another,
                                        muteLogs=not inspectEquals)
    assert False == ObjectHelper.equals(expected, [
        MyDto(None, None, None),
        MyDto(None, None, None),
        MyDto(None, None, None)
    ])
예제 #7
0
def equal_whenListOfDictionaries():
    # arrange
    null = 'null'
    LIST_OF_DICTIONARIES = [{
        "myAttribute":
        "NW2",
        "myOther": {
            "myAttribute": "34PDZB"
        },
        "myThirdList": [{
            "my": {
                "myAttribute": "X1HC",
                "myOther": {
                    "myAttribute": "34PDZB"
                },
                "myThirdList": null
            },
            "myAttribute": 9
        }]
    }, {
        "myAttribute":
        "",
        "myOther":
        null,
        "myThirdList": [{
            "my": {
                "myAttribute": "U",
                "myOther": null,
                "myThirdList": null
            },
            "myAttribute": 3
        }]
    }, {
        "myAttribute":
        "HNQ7QKW2",
        "myOther": {
            "myAttribute": "V9OXKD8"
        },
        "myThirdList": [{
            "my": {
                "myAttribute": "PVYA",
                "myOther": {
                    "myAttribute": "V9OXKD8"
                },
                "myThirdList": null
            },
            "myAttribute": 10
        }]
    }]
    DIFFERENT_LIST_OF_DICTIONARIES = [{
        "myAttribute":
        "NW2",
        "myOther": {
            "myAttribute": "34PDZB"
        },
        "myThirdList": [{
            "my": {
                "myAttribute": "X1HC",
                "myOther": {
                    "myAttribute": RandomHelper.integer()
                },
                "myThirdList": null
            },
            "myAttribute": 9
        }]
    }, {
        "myAttribute":
        "",
        "myOther":
        null,
        "myThirdList": [{
            "my": {
                "myAttribute": "U",
                "myOther": null,
                "myThirdList": null
            },
            "myAttribute": 3
        }]
    }, {
        "myAttribute":
        "HNQ7QKW2",
        "myOther": {
            "myAttribute": "V9OXKD8"
        },
        "myThirdList": [{
            "my": {
                "myAttribute": "PVYA",
                "myOther": {
                    "myAttribute": "V9OXKD8"
                },
                "myThirdList": null
            },
            "myAttribute": 10
        }]
    }]

    # act
    # assert
    assert ObjectHelper.equals(LIST_OF_DICTIONARIES, [{
        "myAttribute":
        "NW2",
        "myOther": {
            "myAttribute": "34PDZB"
        },
        "myThirdList": [{
            "my": {
                "myAttribute": "X1HC",
                "myOther": {
                    "myAttribute": "34PDZB"
                },
                "myThirdList": null
            },
            "myAttribute": 9
        }]
    }, {
        "myAttribute":
        "",
        "myOther":
        null,
        "myThirdList": [{
            "my": {
                "myAttribute": "U",
                "myOther": null,
                "myThirdList": null
            },
            "myAttribute": 3
        }]
    }, {
        "myAttribute":
        "HNQ7QKW2",
        "myOther": {
            "myAttribute": "V9OXKD8"
        },
        "myThirdList": [{
            "my": {
                "myAttribute": "PVYA",
                "myOther": {
                    "myAttribute": "V9OXKD8"
                },
                "myThirdList": null
            },
            "myAttribute": 10
        }]
    }])
    assert False == ObjectHelper.equals(LIST_OF_DICTIONARIES, [{}, {}, {}])
    assert False == ObjectHelper.equals(LIST_OF_DICTIONARIES,
                                        DIFFERENT_LIST_OF_DICTIONARIES)