def test_client_returned_record():
    ci = FooClientInterface.create()

    number1 = 10
    number2 = -10
    some_record = FooSomeOtherRecord(number1, number2)

    record_id = 28
    content = "Hello World"
    set_rec = FooClientReturnedRecord(record_id, content, some_record)

    ci.set_record(set_rec)
    get_rec = ci.get_record()

    assert set_rec.record_id == record_id and \
           set_rec.content == content and \
           set_rec.some_record.__dict__ == some_record.__dict__

    print("Forcing garbage collection in test_client_interface_py")
    set_rec = None
    get_rec = None
    some_record = None
    gc.collect()

    FooClientReturnedRecord.check_c_data_set_empty()
    FooSomeOtherRecord.check_c_data_set_empty()
Пример #2
0
def test_client_returned_record():
    ci = FooClientInterface.create()

    number1 = 10
    number2 = -10
    some_record = FooSomeOtherRecord(number1, number2)

    record_id = 28
    content = "Hello World"
    set_rec = FooClientReturnedRecord(record_id, content, some_record)

    ci.set_record(set_rec)
    get_rec = ci.get_record()

    assert set_rec.record_id == record_id and \
           set_rec.content == content and \
           set_rec.some_record.__dict__ == some_record.__dict__

    print ("Forcing garbage collection in test_client_interface_py")
    set_rec = None
    get_rec = None
    some_record = None
    gc.collect()

    FooClientReturnedRecord.check_c_data_set_empty()
    FooSomeOtherRecord.check_c_data_set_empty()
def test_client_returned_record_derivings():
    number1 = 10
    number2 = 20
    some_record_1a = FooSomeOtherRecord(number1, number2)
    some_record_1b = FooSomeOtherRecord(number1, number2)
    some_record_1c = some_record_1a

    some_record_less_1 = FooSomeOtherRecord(number1 - 2, number2)
    some_record_less_2 = FooSomeOtherRecord(number1, number2 - 2)
    some_record_greater_1 = FooSomeOtherRecord(number1 + 2, number2)
    some_record_greater_2 = FooSomeOtherRecord(number1 + 2, number2 - 2)

    eq_neq(some_record_1a, some_record_1b, some_record_1c, some_record_less_1,
           some_record_greater_1)
    lt_gt(some_record_less_1, some_record_1a)
    lt_gt(some_record_less_2, some_record_1a)

    pytest.raises(AssertionError, lt_gt, some_record_greater_2, some_record_1a)

    record_id = 28
    content = "Hello World"
    rec_1a = FooClientReturnedRecord(record_id, content, some_record_1a)
    rec_1b = FooClientReturnedRecord(record_id, content, some_record_1b)
    rec_1c = rec_1a

    rec_less_1 = FooClientReturnedRecord(record_id - 2, content,
                                         some_record_1a)
    rec_less_2 = FooClientReturnedRecord(record_id, "A " + content,
                                         some_record_1a)
    rec_less_3 = FooClientReturnedRecord(record_id, content,
                                         some_record_less_1)
    rec_greater_1 = FooClientReturnedRecord(record_id + 2, content,
                                            some_record_1b)

    eq_neq(rec_1a, rec_1b, rec_1c, rec_less_1, rec_greater_1)
    lt_gt(rec_less_1, rec_1a)
    lt_gt(rec_less_2, rec_1a)
    lt_gt(rec_less_3, rec_1a)
 def check_c_data_set_empty():
     assert len(ListRecordFooSomeOtherRecordHelper.c_data_set) == 0
     FooSomeOtherRecord.check_c_data_set_empty()
 def check_c_data_set_empty():
     assert len(ListRecordFooSomeOtherRecordHelper.c_data_set) == 0
     FooSomeOtherRecord.check_c_data_set_empty()
Пример #6
0
 def python_create_foo_some_other_record(number1,number2):
     py_rec = FooSomeOtherRecord(
         CPyPrimitive.toPy(number1),
         CPyPrimitive.toPy(number2))
     return CPyRecord.fromPy(FooSomeOtherRecord.c_data_set, py_rec) #to do: can be optional?
 def check_c_data_set_empty():
     assert len(FooClientReturnedRecord.c_data_set) == 0
     FooSomeOtherRecord.check_c_data_set_empty()
Пример #8
0
def test_set_get_record():
    ci = FooContainersInterface.create()

    optional_list_int = None
    list_int = list([5, 6, 7, 8, 9])
    list_int_2 = list_int  # possible to use same list as argument twice, as we use multiset
    list_binary = list([b'some_binary', b'some_other_binary'])
    list_string1 = list(['hi', '', 'bye'])
    list_string2 = list(['hi2', '', 'bye2'])
    list_list_string = list([list_string1, list_string2])
    number1 = 10
    number2 = -10
    some_record_1 = FooSomeOtherRecord(number1, number2)
    some_record_2 = FooSomeOtherRecord(number1 * 2, number2 * 2)
    list_record = list([some_record_1, some_record_2])
    set_record = set([some_record_1, some_record_1])
    optional_map_string_int = None
    map_string_int = dict([('josh', 4139), ('anna', 4127), ('jack', 4098)])
    map_string_string = dict([('josh', 'val1'), ('anna', 'val2'),
                              ('jack', 'val3')])
    list_date1 = list([datetime.datetime(2007, 4, 17, 1, 2, 3)])
    list_date2 = list([datetime.datetime(2007, 4, 17, 1, 2, 4)])
    map_int_list_date = dict([(18, list_date1), (5, list_date2)])
    optional_set_string = None
    set_string = set(['hi', 'bye'])
    map_int_set_string = dict([(18, set_string)])
    map_optional_int_set_string = dict([(18, set_string), (None, set_string)])
    list_optional_binary = list([b'some_binary', None])
    map_optional_string_optional_string = dict([('anna', None), (None, None)])
    set_optional_string = set(['hi', None])
    # set_record = set(list[some_record_1, some_record_2])

    # Passing optional list as argument
    ci.set_optional_list_int(list_int)
    assert ci.get_optional_list_int() == list_int
    ci.set_optional_list_int(None)
    assert ci.get_optional_list_int() is None

    # Passing optional map as argument
    ci.set_optional_map_string_int(map_string_int)
    assert ci.get_optional_map_string_int() == map_string_int
    ci.set_optional_map_string_int(None)
    assert ci.get_optional_map_string_int() is None

    # Passing non-Nones for the optional arguments
    set_get(ci, list_int_2, list_int, list_binary, list_binary, list_list_string, \
     list_record, map_string_int, map_string_int, map_string_string, map_string_string, map_int_list_date, \
       set_string, set_string, set_string, map_int_set_string, map_optional_int_set_string)

    set_get(ci, list(), list(), list(), list(), list(list()), list(), dict(),
            dict(), dict(), dict(), dict(), set(), set(), set(), dict(),
            dict())

    # Passing Nones for the optional arguments
    set_get(ci, optional_list_int, list_int, list_binary, list_optional_binary, list_list_string, \
     list_record, optional_map_string_int, map_string_int, map_string_string, map_optional_string_optional_string, map_int_list_date, \
      optional_set_string, set_string, set_optional_string, map_int_set_string, map_optional_int_set_string)

    # Passing non-None for optional record argument
    set_get_optional(ci, list(), list(), list(), list(), list(list()), list(),
                     dict(), dict(), dict(), dict(), dict(), set(), set(),
                     set(), dict(), dict())
    set_get_optional(ci, optional_list_int, list_int, list_binary, list_optional_binary, list_list_string, \
     list_record, optional_map_string_int, map_string_int, map_string_string, map_optional_string_optional_string, map_int_list_date, \
      optional_set_string, set_string, set_optional_string, map_int_set_string, map_optional_int_set_string)

    # Passing None for optional record argument
    ci.set_optional_containers_record(None)
    get_rec = ci.get_optional_containers_record()
    assert get_rec is None

    print("Forcing garbage collection")
    set_rec = None
    get_rec = None
    some_record_2 = None
    some_record_1 = None
    list_record = None
    # set_record = None
    list_string1 = None
    list_string2 = None
    list_list_string = None

    list_date1 = None
    list_date2 = None
    map_int_list_date = None
    gc.collect()

    FooContainersRecord.check_c_data_set_empty()
    FooSomeOtherRecord.check_c_data_set_empty()
Пример #9
0
 def on_changes_record_returned(self, n1, n2):
     return FooSomeOtherRecord(n1,n2)