koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame^] | 1 | import shutil |
| 2 | import tempfile |
| 3 | import contextlib |
| 4 | |
| 5 | |
| 6 | from oktest import ok, main, test |
| 7 | |
| 8 | |
| 9 | from wally.storage import make_storage |
| 10 | |
| 11 | |
| 12 | @contextlib.contextmanager |
| 13 | def in_temp_dir(): |
| 14 | dname = tempfile.mkdtemp() |
| 15 | try: |
| 16 | yield dname |
| 17 | finally: |
| 18 | shutil.rmtree(dname) |
| 19 | |
| 20 | |
| 21 | def test_basic(): |
| 22 | with in_temp_dir() as root: |
| 23 | values = { |
| 24 | "int": 1, |
| 25 | "str/1": "test", |
| 26 | "bytes/2": b"test", |
| 27 | "none/s/1": None, |
| 28 | "bool/xx/1/2/1": None, |
| 29 | "float/s/1": 1.234, |
| 30 | "list": [1, 2, "3"], |
| 31 | "dict": {1: 3, "2": "4", "1.2": 1.3} |
| 32 | } |
| 33 | |
| 34 | with make_storage(root, existing=False) as storage: |
| 35 | for path, val in values.items(): |
| 36 | storage[path] = val |
| 37 | |
| 38 | |
| 39 | with make_storage(root, existing=True) as storage: |
| 40 | for path, val in values.items(): |
| 41 | ok(storage[path]) == val |
| 42 | |
| 43 | |
| 44 | def test_large_arrays(): |
| 45 | pass |
| 46 | |
| 47 | |
| 48 | def test_array_append(): |
| 49 | pass |
| 50 | |
| 51 | |
| 52 | def test_performance(): |
| 53 | pass |