def test_getting_out_of_range_64_bit_values(self, test_output, test_input): # Set the values via a dictionary (set_string, and __setitem__ would also work) test_output.instance.set_dictionary({ "my_uint64": 2**53 + 1, "my_int64": 2**53 + 1 }) sample = send_data(test_output, test_input) with pytest.raises( rti.Error, match=r".*value of my_int64 is too large.*") as execinfo: sample.get_number("my_int64") with pytest.raises( rti.Error, match=r".*value of my_uint64 is too large.*") as execinfo: sample.get_number("my_uint64") # Also check value < -2^53 test_output.instance.set_dictionary({"my_int64": -2**53 - 1}) sample = send_data(test_output, test_input) with pytest.raises( rti.Error, match=r".*value of my_int64 is too large.*") as execinfo: sample.get_number("my_int64") # Check that the maximum values can be retrieved (2^53) test_output.instance.set_dictionary({ "my_uint64": 2**53, "my_int64": -2**53 }) sample = send_data(test_output, test_input) assert sample.get_number("my_uint64") == 2**53 assert sample.get_number("my_int64") == -2**53
def test_large_uint64(self, test_output, test_input): max_int_get = 2**53 # 9007199254740992 max_int_set = 2**53 - 1 # largest integer allowed in set_number test_output.instance.set_number("my_uint64", max_int_set) test_output.instance.set_number("my_int64", -max_int_set) sample = send_data(test_output, test_input) assert sample.get_number("my_uint64") == max_int_set assert sample.get_number("my_int64") == -max_int_set # largest integer allowed in get_number; ok in set_dictionary, which # __setitem__ will also use test_output.instance["my_uint64"] = max_int_get test_output.instance.set_dictionary({"my_int64": -max_int_get}) sample = send_data(test_output, test_input) assert sample.get_number("my_uint64") == max_int_get assert sample.get_number("my_int64") == -max_int_get # too large for get_number, but ok in get_dictionary self.verify_large_integer(test_output, test_input, max_int_get + 1) # 9007199254740999 -> 9007199254741000.0 self.verify_large_integer(test_output, test_input, 9007199254740999) # largest long long self.verify_large_integer(test_output, test_input, 2**63 - 1)
def test_large_integer_type_agnostic_setter(self, test_output, test_input): # Check that the type-agnostic setter can be used to set numbers as strings, # also the values can be supplied as numbers. test_output.instance["my_uint64"] = str(2**53) test_output.instance["my_int64"] = str(-2**53) sample = send_data(test_output, test_input) assert sample["my_uint64"] == 2**53 assert sample["my_int64"] == -2**53 # Check the same but supplying them as numbers (internally they get set via # dictionary in this case) test_output.instance["my_uint64"] = 2**53 test_output.instance["my_int64"] = -2**53 sample = send_data(test_output, test_input) assert sample["my_uint64"] == 2**53 assert sample["my_int64"] == -2**53
def test_convert_from_string_in_dict(self, test_output, test_input, test_dictionary): test_output.instance.set_dictionary({ 'my_long': "10", 'my_double': "3.3", 'my_optional_bool': True, 'my_enum': "1", 'my_string': 'hello', 'my_point': { 'x': "3", 'y': "4" }, 'my_point_alias': { 'x': "30", 'y': "40" }, 'my_union': { 'my_int_sequence': ["10", "20", "30"] }, 'my_int_union': { 'my_long': "222" }, 'my_point_sequence': [{ 'x': "10", 'y': 20 }, { 'x': "11", 'y': "21" }], 'my_int_sequence': ["1", 2, 3], 'my_point_array': [{ 'x': "0", 'y': 0 }, { 'x': 0, 'y': "0" }, { 'x': 0, 'y': 0 }, { 'x': 0, 'y': 0 }, { 'x': 5, 'y': 15 }], 'my_boolean': False, 'my_int64': "-18014398509481984", 'my_uint64': "18014398509481984" }) sample = send_data(test_output, test_input) assert sample.get_dictionary() == test_dictionary
def test_nested_syntax_in_dictionary(self, test_output, test_input): test_output.instance.set_dictionary({"my_point_sequence[2].y": 153}) test_output.instance.set_dictionary({"my_point_sequence[2].x": 111}) test_output.instance["my_point_sequence[3]"] = {"x": 444, "y": 555} sample = send_data(test_output, test_input) assert sample["my_point_sequence[2]"] == {"x": 111, "y": 153} assert sample["my_point_sequence[3]"] == {"x": 444, "y": 555}
def verify_large_integer(self, output, input, number): with pytest.raises( rti.Error, match=r".*value of my_uint64 is too large.*") as execinfo: output.instance.set_number("my_uint64", number) with pytest.raises( rti.Error, match=r".*value of my_int64 is too large.*") as execinfo: output.instance.set_number("my_int64", -number) output.instance.set_dictionary({ "my_uint64": number, "my_int64": -number }) sample = send_data(output, input) dictionary = sample.get_dictionary() assert dictionary["my_uint64"] == number assert dictionary["my_int64"] == -number with pytest.raises( rti.Error, match=r".*value of my_uint64 is too large.*") as execinfo: sample.get_number("my_uint64") with pytest.raises( rti.Error, match=r".*value of my_int64 is too large.*") as execinfo: sample.get_number("my_int64")
def test_reset_sequence(self, test_output, test_input): test_output.instance.set_number("my_union.my_int_sequence[2]", 10) test_output.instance.set_number("my_point.x", 3) test_output.instance["my_point_sequence[1].x"] = 44 sample = send_data(test_output, test_input) assert sample.get_number("my_point.x") == 3 assert sample.get_number("my_union.my_int_sequence#") == 3 assert sample.get_number("my_point_sequence#") == 2 test_output.instance.set_dictionary({'my_int_sequence': []}) sample = send_data(test_output, test_input) assert sample.get_number("my_int_sequence#") == 0 # The other fields are unchanged: assert sample.get_number("my_point.x") == 3 assert sample.get_number("my_point_sequence#") == 2
def test_error_in_dictionary(self, test_output, test_input): with pytest.raises(rti.Error) as excinfo: # sequence max length is 10 test_output.instance.set_dictionary({"my_int_sequence": [10] * 11}) # Make sure the previous error didn't corrupt the instance test_output.instance.set_dictionary({"my_int_sequence": [10] * 10}) sample = send_data(test_output, test_input) assert sample["my_int_sequence"] == [10] * 10
def test_set_list_with_setitem(self, test_output, test_input): int_seq = [11, 22, 33] point_seq = [{"x": 100, "y": 200}, {"x": 300, "y": 400}] test_output.instance["my_int_sequence"] = int_seq test_output.instance["my_point_sequence"] = point_seq sample = send_data(test_output, test_input) assert sample["my_int_sequence"] == int_seq assert sample["my_point_sequence"] == point_seq
def test_large_integer_communication_with_dictionaries( self, test_output, test_input): # When dictionaries are used to set / get the sample there are no restrictions # on the size of the integers. dict_send = {"my_uint64": 2**53, "my_int64": -2**53} test_output.instance.set_dictionary(dict_send) dict_receive = send_data(test_output, test_input).get_dictionary() assert dict_receive["my_uint64"] == dict_send["my_uint64"] assert dict_receive["my_int64"] == dict_send["my_int64"]
def test_clear_within_complex_list(self, test_output, test_input): # Initialize point sequence to contain 3 points point_seq = [{ "x": 100, "y": 200 }, { "x": 300, "y": 400 }, { "x": 500, "y": 600 }] test_output.instance["my_point_sequence"] = point_seq sample = send_data(test_output, test_input) assert sample["my_point_sequence"] == point_seq # Now clear one of the complex elements within the sequence point_seq = [{"x": 100, "y": 200}, None, {"x": 500, "y": 600}] test_output.instance["my_point_sequence"] = point_seq sample = send_data(test_output, test_input) assert sample["my_point_sequence[0]"] == {"x": 100, "y": 200} assert sample["my_point_sequence[1]"] == {"x": 0, "y": 0} assert sample["my_point_sequence[2]"] == {"x": 500, "y": 600}
def test_large_integers_are_returned_as_int_getitem( self, test_output, test_input): # Check that the type-agnostic getter can be used to obtain values outside of # get_number's range. If they are outside of this range they will be instance # of int. test_output.instance.set_dictionary({ "my_uint64": str(2**53 + 1), "my_int64": str(-2**53 - 1) }) sample = send_data(test_output, test_input) assert isinstance(sample["my_uint64"], int) assert isinstance(sample["my_int64"], int) assert sample["my_uint64"] == 2**53 + 1 assert sample["my_int64"] == -2**53 - 1
def test_unbounded(self): with open_test_connector( "MyParticipantLibrary::TestUnbounded") as connector: output = connector.get_output("TestPublisher::TestWriter") input = connector.get_input("TestSubscriber::TestReader") output.instance.set_dictionary({ "my_sequence": [44] * 200, "my_string": "A" * 200 }) sample = send_data(output, input) assert sample["my_sequence"] == [44] * 200 assert sample["my_string"] == "A" * 200
def test_smaller_integers_are_returned_as_float_by_getitem( self, test_output, test_input): # Check that the type-agnostic getter can be used to obtain values inside of # get_number's range. If they are inside of this range they will be instance # of float. test_output.instance.set_dictionary({ "my_uint64": str(2**53), "my_int64": str(-2**53) }) sample = send_data(test_output, test_input) # They will be floats since they have come via Lua assert isinstance(sample["my_uint64"], float) assert isinstance(sample["my_int64"], float) assert sample["my_uint64"] == 2**53 assert sample["my_int64"] == -2**53
def test_64_bit_int_communication_with_get_set_string( self, test_output, test_input): # Check that the set_string and get_string operations work with large numbers large_numeric_value = 2**53 large_negative_numeric_value = -2**53 test_output.instance.set_string("my_uint64", str(large_numeric_value)) test_output.instance.set_string("my_int64", str(large_negative_numeric_value)) sample = send_data(test_output, test_input) assert sample.get_string("my_uint64") == str(large_numeric_value) assert isinstance(sample.get_string("my_uint64"), str) assert int(sample.get_string("my_uint64")) == large_numeric_value assert sample.get_string("my_int64") == str( large_negative_numeric_value) assert int( sample.get_string("my_int64")) == large_negative_numeric_value assert isinstance(sample.get_string("my_int64"), str)
def test_error_in_dictionary2(self, test_output, test_input): with pytest.raises(rti.Error) as excinfo: # error parsing an element is different from error parsing sequence itself test_output.instance.set_dictionary({ "my_point_sequence": [{ "x": 1, "y": 2 }, { "x": 34, "bad": 40 }] }) # Make sure the previous error didn't corrupt the instance test_output.instance.set_dictionary( {"my_point_sequence": [{ "x": 1, "y": 2 }, { "x": 34, "y": 40 }]}) sample = send_data(test_output, test_input) assert sample["my_point_sequence[1].y"] == 40
def test_numeric_string(self, test_output, test_input): test_output.instance["my_string"] = "1234" sample = send_data(test_output, test_input) # A side effect of CON-139: __getitem__ automatically parses strings and # returns them as numbers if they represent a number assert sample["my_string"] == 1234
def test_clear_member_with_setitem(self, test_output, test_input): test_output.instance['my_optional_bool'] = None sample = send_data(test_output, test_input) assert sample['my_optional_bool'] is None
def test_set_enum_with_name(self, test_output, test_input): # Test that it is possible to set an enum via its name test_output.instance.set_dictionary({"my_enum": "GREEN"}) sample = send_data(test_output, test_input) assert sample["my_enum"] == 1
def test_set_boolean_as_number(self, test_output, test_input): test_output.instance.set_number("my_optional_bool", 1) sample = send_data(test_output, test_input) assert sample["my_optional_bool"] == True