|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +"""Unit tests for Pyjsonviewer.""" |
| 5 | + |
| 6 | +import sys |
| 7 | +import traceback |
| 8 | +sys.path.insert(0, "../pyjsonviewer") |
| 9 | +import tkinter as tk |
| 10 | +from pyjsonviewer import JSONTreeFrame |
| 11 | + |
| 12 | + |
| 13 | +def test_dictionary_file(): |
| 14 | + """ |
| 15 | + should read dictionary file okay |
| 16 | + """ |
| 17 | + # given |
| 18 | + root: Tk = tk.Tk() |
| 19 | + app = JSONTreeFrame(root, json_path="../dat/dictionary.json") |
| 20 | + |
| 21 | + # when |
| 22 | + children = app.get_all_children(app.tree) |
| 23 | + # print([app.tree.item(item_id, 'text') for item_id in children]) |
| 24 | + |
| 25 | + # then |
| 26 | + assert len(children) == 31 |
| 27 | + |
| 28 | + |
| 29 | +def test_list_file(): |
| 30 | + """ |
| 31 | + should read list file okay |
| 32 | + """ |
| 33 | + # given |
| 34 | + root: Tk = tk.Tk() |
| 35 | + app = JSONTreeFrame(root, json_path="../dat/list.json") |
| 36 | + |
| 37 | + # when |
| 38 | + children = app.get_all_children(app.tree) |
| 39 | + # print([app.tree.item(item_id, 'text') for item_id in children]) |
| 40 | + |
| 41 | + # then |
| 42 | + assert len(children) == 18 |
| 43 | + |
| 44 | + |
| 45 | +def test_nested_file(): |
| 46 | + """ |
| 47 | + should read list file okay |
| 48 | + """ |
| 49 | + # given |
| 50 | + root: Tk = tk.Tk() |
| 51 | + app = JSONTreeFrame(root, json_path="../dat/nested.json") |
| 52 | + |
| 53 | + # when |
| 54 | + children = app.get_all_children(app.tree) |
| 55 | + print([app.tree.item(item_id, 'text') for item_id in children]) |
| 56 | + |
| 57 | + # then |
| 58 | + assert len(children) == 33 |
| 59 | + |
| 60 | + |
| 61 | +def test_search(): |
| 62 | + """ |
| 63 | + search should not break in case of numeric fields |
| 64 | + """ |
| 65 | + # given |
| 66 | + root: Tk = tk.Tk() |
| 67 | + app = JSONTreeFrame(root, json_path="../dat/list.json") |
| 68 | + |
| 69 | + |
| 70 | + try: |
| 71 | + x = app.find("fuzzy") |
| 72 | + except AttributeError as err: |
| 73 | + # AttributeError: 'int' object has no attribute 'lower' |
| 74 | + assert False |
| 75 | + assert True |
| 76 | + |
0 commit comments