forked from slightlynybbled/tk_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_BinaryLabel.py
More file actions
136 lines (86 loc) · 2.18 KB
/
test_BinaryLabel.py
File metadata and controls
136 lines (86 loc) · 2.18 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import tkinter as tk
import pytest
from tk_tools import BinaryLabel
from tests.test_basic import root
@pytest.fixture
def bl(root):
bl_widget = BinaryLabel(root)
bl_widget.grid()
yield bl_widget
def test_creation(root):
bl = BinaryLabel(root)
bl.grid()
assert bl.get() == 0
def test_creation_with_value(root):
bl = BinaryLabel(root, value=101)
bl.grid()
assert bl.get() == 101
def test_change_value(bl):
bl.set(101)
assert bl.get() == 101
bl.set(10)
assert bl.get() == 10
def test_change_value_too_large(bl):
with pytest.raises(ValueError):
bl.set(0x100)
def test_get_bit(bl):
bl.set(0x55)
assert bl.get_bit(0) == 1
assert bl.get_bit(1) == 0
assert bl.get_bit(2) == 1
assert bl.get_bit(3) == 0
assert bl.get_bit(4) == 1
assert bl.get_bit(5) == 0
assert bl.get_bit(6) == 1
assert bl.get_bit(7) == 0
with pytest.raises(ValueError):
bl.get_bit(8)
def test_toggle_bit(bl):
bl.set(0x55)
assert bl.get_bit(0) == 1
bl.toggle_bit(0)
assert bl.get_bit(0) == 0
with pytest.raises(ValueError):
bl.toggle_bit(8)
def test_set_and_clear_bit(bl):
bl.set(0x55)
assert bl.get_bit(0) == 1
bl.clear_bit(0)
assert bl.get_bit(0) == 0
bl.set_bit(0)
assert bl.get_bit(0) == 1
with pytest.raises(ValueError):
bl.clear_bit(8)
with pytest.raises(ValueError):
bl.set_bit(8)
def test_get_msb_and_lsb(bl):
assert bl.get_msb() == 0
assert bl.get_lsb() == 0
bl.set(0xff)
assert bl.get_msb() == 1
assert bl.get_lsb() == 1
def test_set_msb(bl):
assert bl.get() == 0
bl.set_msb()
assert bl.get() == 0x80
def test_clear_msb(bl):
bl.set(0xff)
assert bl.get() == 0xff
bl.clear_msb()
assert bl.get() == 0x7f
def test_set_lsb(bl):
assert bl.get() == 0
bl.set_lsb()
assert bl.get() == 0x01
def test_clear_lsb(bl):
bl.set(0xff)
assert bl.get() == 0xff
bl.clear_lsb()
assert bl.get() == 0xfe
def test_toggle_msb_lsb(bl):
bl.toggle_msb()
bl.toggle_lsb()
assert bl.get() == 0x81
bl.toggle_msb()
bl.toggle_lsb()
assert bl.get() == 0x00