summaryrefslogtreecommitdiff
path: root/tests/test_util.py
blob: 7eb63d53ac7693ffd41bec6efd266a87a2aee77b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
HappyBase utility tests.
"""

from nose.tools import assert_equal, assert_less

import happybase.util as util


def test_camel_case_to_pep8():
    def check(lower_cc, upper_cc, correct):

        x1 = util.camel_case_to_pep8(lower_cc)
        x2 = util.camel_case_to_pep8(upper_cc)
        assert_equal(correct, x1)
        assert_equal(correct, x2)

        y1 = util.pep8_to_camel_case(x1, True)
        y2 = util.pep8_to_camel_case(x2, False)
        assert_equal(upper_cc, y1)
        assert_equal(lower_cc, y2)

    examples = [('foo', 'Foo', 'foo'),
                ('fooBar', 'FooBar', 'foo_bar'),
                ('fooBarBaz', 'FooBarBaz', 'foo_bar_baz'),
                ('fOO', 'FOO', 'f_o_o')]

    for a, b, c in examples:
        yield check, a, b, c


def test_str_increment():
    def check(s_hex, expected):
        s = s_hex.decode('hex')
        v = util.str_increment(s)
        v_hex = v.encode('hex')
        assert_equal(expected, v_hex)
        assert_less(s, v)

    test_values = [
        ('00', '01'),
        ('01', '02'),
        ('fe', 'ff'),
        ('1234', '1235'),
        ('12fe', '12ff'),
        ('12ff', '13'),
        ('424242ff', '424243'),
        ('4242ffff', '4243'),
    ]

    assert util.str_increment('\xff\xff\xff') is None

    for s, expected in test_values:
        yield check, s, expected