コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
    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)
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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()
コード例 #8
0
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
コード例 #9
0
def test_standardize_str_1():
    # six.text_type is 'unicode' in Python 2
    assert standardize_strings('abc', six.text_type) == u'abc'
コード例 #10
0
def test_standardize_str_2():
    # six.binary_type is 'str' in Python 2
    assert standardize_strings(u'abc', six.binary_type) == 'abc'
コード例 #11
0
def test_standardize_str_9():
    assert standardize_strings(54, None) == 54
コード例 #12
0
def test_standardize_str_10():
    with pytest.raises(TypeError):
        assert standardize_strings("64", int)
コード例 #13
0
def test_standardize_str_error_with_py3():
    with raises(AssertionError):
        standardize_strings('123')
コード例 #14
0
def test_standardize_str_1():
    assert standardize_strings('abc', unicode) == u'abc'
コード例 #15
0
def test_standardize_str_2():
    assert standardize_strings(u'abc', str) == 'abc'
コード例 #16
0
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
コード例 #17
0
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