diff options
author | Wouter Bolsterlee <uws@xs4all.nl> | 2012-05-23 17:22:44 +0200 |
---|---|---|
committer | Wouter Bolsterlee <uws@xs4all.nl> | 2012-05-23 17:22:44 +0200 |
commit | e84aca22e6f2996bc140bed1448edb546c10975b (patch) | |
tree | f136e6a50b66742a92a51ea6520d8d2be1e1a99f /tests | |
parent | 7fc18115414c91ea97b8be706eb2f204c1081bf9 (diff) | |
download | happybase-e84aca22e6f2996bc140bed1448edb546c10975b.tar.gz |
Implement a str_increment() utility function
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_util.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/tests/test_util.py b/tests/test_util.py index 1f810dd..7eb63d5 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -2,21 +2,21 @@ HappyBase utility tests. """ -from nose.tools import assert_equal +from nose.tools import assert_equal, assert_less -import happybase.util +import happybase.util as util def test_camel_case_to_pep8(): def check(lower_cc, upper_cc, correct): - x1 = happybase.util.camel_case_to_pep8(lower_cc) - x2 = happybase.util.camel_case_to_pep8(upper_cc) + 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 = happybase.util.pep8_to_camel_case(x1, True) - y2 = happybase.util.pep8_to_camel_case(x2, False) + 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) @@ -27,3 +27,28 @@ def test_camel_case_to_pep8(): 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 |