|
| 1 | +import unittest |
| 2 | +import lib.utils as utils |
| 3 | + |
| 4 | +class TestUtils(unittest.TestCase): |
| 5 | + |
| 6 | + def test_bytes_to_str(self): |
| 7 | + byte_str = b'abc' |
| 8 | + string = utils.bytes_to_str(byte_str) |
| 9 | + self.assertTrue(isinstance(string, str)) |
| 10 | + |
| 11 | + def test_assert_str(self): |
| 12 | + # negative case |
| 13 | + byte_str = b'abc' |
| 14 | + try: |
| 15 | + utils.assert_str(byte_str) |
| 16 | + except Exception as e: |
| 17 | + self.assertTrue(str(e) == ValueError) |
| 18 | + |
| 19 | + # positive case |
| 20 | + string = 'abc' |
| 21 | + utils.assert_str(string) |
| 22 | + |
| 23 | + def test_assert_bytes(self): |
| 24 | + # negative case |
| 25 | + string = 'abc' |
| 26 | + try: |
| 27 | + utils.assert_bytes(byte_str) |
| 28 | + except Exception as e: |
| 29 | + self.assertTrue(str(e) == ValueError) |
| 30 | + |
| 31 | + # positive case |
| 32 | + byte_str = b'abc' |
| 33 | + utils.assert_bytes(byte_str) |
| 34 | + |
| 35 | + |
| 36 | + def test_extract_schema_from_snapshot(self): |
| 37 | + snapshot_path = '00000000000000000003.snap' |
| 38 | + v = utils.extract_schema_from_snapshot(snapshot_path) |
| 39 | + self.assertTrue(v == 3) |
| 40 | + |
| 41 | + def test_just_and_trim(self): |
| 42 | + s = utils.just_and_trim('tarantool', 4) |
| 43 | + self.assertTrue(s == 4) |
| 44 | + |
| 45 | + def test_xlog_rows(self): |
| 46 | + snapshot_path = '00000000000000000003.snap' |
| 47 | + iterator = utils.xlog_rows(snapshot_path) |
| 48 | + if next(iterator, sentinel) is sentinel: |
| 49 | + print('iterator was empty') |
| 50 | + |
| 51 | + def test_prefix_each_line(self): |
| 52 | + prefix = '>' |
| 53 | + data = """ |
| 54 | + hello1 |
| 55 | + hello2 |
| 56 | + hello3 |
| 57 | + """ |
| 58 | + data_with_prefix = """ |
| 59 | + > |
| 60 | + > hello1 |
| 61 | + > hello2 |
| 62 | + > hello3 |
| 63 | + """ |
| 64 | + prefixed = utils.prefix_each_line(prefix, data) |
| 65 | + self.assertMultiLineEqual(prefixed, data_with_prefix) |
| 66 | + |
| 67 | + def test_set_fd_cloexec(self): |
| 68 | + pass |
| 69 | + |
| 70 | + def test_format_process(self): |
| 71 | + pass |
| 72 | + |
| 73 | + def test_safe_makedirs(self): |
| 74 | + pass |
| 75 | + |
| 76 | + def test_warn_unix_socket(self): |
| 77 | + pass |
| 78 | + |
| 79 | + def test_signame(self): |
| 80 | + pass |
| 81 | + |
| 82 | + def test_signum(self): |
| 83 | + pass |
| 84 | + |
| 85 | + def test_find_in_path(self): |
| 86 | + pass |
| 87 | + |
| 88 | + def test_find_port(self): |
| 89 | + pass |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + unittest.main() |
0 commit comments