def test_standardize_str_5(): input_val_ = (145, 964, 84, ['ghjfgh', 64], [(84, 9.254, b'trdf', 645), '456', u'784', 'sdfg']) output_val = (145, 964, 84, [u'ghjfgh', 64], [(84, 9.254, b'trdf', 645), u'456', u'784', u'sdfg']) # six.text_type is 'unicode' in Python 2 assert standardize_strings(input_val_, six.text_type) == output_val
def test_standardize_str_6(): input_val_ = (145, 964, 84, (u'ghjfgh', 64), ([84, 9.254, b'trdf', 645], u'456', u'784', 'sdfg')) output_val = (145, 964, 84, ('ghjfgh', 64), ([84, 9.254, b'trdf', 645], '456', '784', 'sdfg')) # six.binary_type is 'str' in Python 2 assert standardize_strings(input_val_, six.binary_type) == output_val
def execute(self, *args, **kwargs): """Call the function encapsulated by the current instance""" if six.PY2: args = standardize_strings(args, strtype=self.str_standardization, encoding=self.str_std_encoding) # Call the rpc method, as standard python function return self.function(*args, **kwargs)
def test_standardize_str_4(): input_val_ = [ 145, 964, 84, [u'ghjfgh', 64], [[84, 9.254, b'trdf', 645], u'456', u'784', 'sdfg'] ] output_val = [ 145, 964, 84, ['ghjfgh', 64], [[84, 9.254, b'trdf', 645], '456', '784', 'sdfg'] ] # six.binary_type is 'str' in Python 2 assert standardize_strings(input_val_, six.binary_type) == output_val
def test_standardize_str_8(): in_dict = { 'a': 456, 'b': [84, 5.1, u'strdfg', u'trdt'], 'pp': { 'x': 32, 'y': [u'rtg', 'poi', u'aze'] }, } expected_out = { 'a': 456, 'b': [84, 5.1, 'strdfg', 'trdt'], 'pp': { 'x': 32, 'y': ['rtg', 'poi', 'aze'] }, } assert standardize_strings(in_dict, str) == expected_out
def test_standardize_str_8(): input_dict = { 'a': 456, 'b': [84, 5.1, u'strdfg', u'trdt'], 'pp': { 'x': 32, 'y': [u'rtg', 'poi', u'aze'] }, } expected_out = { 'a': 456, 'b': [84, 5.1, 'strdfg', 'trdt'], 'pp': { 'x': 32, 'y': ['rtg', 'poi', 'aze'] }, } # six.binary_type is 'str' in Python 2 assert standardize_strings(input_dict, six.binary_type) == expected_out
def test_standardize_str_error_with_py3(): with pytest.raises(AssertionError) as excpinfo: standardize_strings('123') assert 'python 2 only' in str(excpinfo.value).lower()
def test_standardize_str_6(): in_list = (145, 964, 84, (u'ghjfgh', 64), ([84, 9.254, b'trdf', 645], u'456', u'784', 'sdfg')) expected_out = (145, 964, 84, ('ghjfgh', 64), ([84, 9.254, b'trdf', 645], '456', '784', 'sdfg')) assert standardize_strings(in_list, str) == expected_out
def test_standardize_str_1(): # six.text_type is 'unicode' in Python 2 assert standardize_strings('abc', six.text_type) == u'abc'
def test_standardize_str_2(): # six.binary_type is 'str' in Python 2 assert standardize_strings(u'abc', six.binary_type) == 'abc'
def test_standardize_str_9(): assert standardize_strings(54, None) == 54
def test_standardize_str_10(): with pytest.raises(TypeError): assert standardize_strings("64", int)
def test_standardize_str_error_with_py3(): with raises(AssertionError): standardize_strings('123')
def test_standardize_str_1(): assert standardize_strings('abc', unicode) == u'abc'
def test_standardize_str_2(): assert standardize_strings(u'abc', str) == 'abc'
def test_standardize_str_5(): in_list = (145, 964, 84, ['ghjfgh', 64], [(84, 9.254, b'trdf', 645), '456', u'784', 'sdfg']) expected_out = (145, 964, 84, [u'ghjfgh', 64], [(84, 9.254, b'trdf', 645), u'456', u'784', u'sdfg']) assert standardize_strings(in_list, unicode) == expected_out
def test_standardize_str_4(): in_list = [145, 964, 84, [u'ghjfgh', 64], [[84, 9.254, b'trdf', 645], u'456', u'784', 'sdfg']] expected_out = [145, 964, 84, ['ghjfgh', 64], [[84, 9.254, b'trdf', 645], '456', '784', 'sdfg']] assert standardize_strings(in_list, str) == expected_out