-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·103 lines (81 loc) · 3.03 KB
/
test
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
#!/usr/bin/env python3
import sys
import re
from macgen import read_OUIs_from_file
from mac import MAC
def test_load():
return read_OUIs_from_file('test_input_macs.txt')
def test_find_mac_without_comments():
OUI = '00:22:22'
mac = MAC.find_by_OUI(OUI)
assert mac.OUI == OUI
assert mac.vendor == 'Schaffne'
assert mac.full_vendor_name == 'Schaffner Deutschland GmbH'
assert mac.comment is None
assert mac._OUI_as_list == OUI.split(':')
def test_find_mac_with_comments():
OUI = '00:00:D1'
mac = MAC.find_by_OUI(OUI)
assert mac.OUI == OUI
assert mac.vendor == 'Adaptec'
assert mac.full_vendor_name == 'Adaptec, Inc.'
assert mac.comment == '# "Nodem" product'
assert mac._OUI_as_list == OUI.split(':')
def test_find_mac_regardless_separator():
OUI = '00:00:D1'
mac = MAC.find_by_OUI(OUI)
assert mac.OUI == OUI
OUI = '00-22-22'
mac = MAC.find_by_OUI(OUI)
assert mac.OUI == OUI.replace('-', ':')
def test_generate():
mac = macs[100]
generated_mac = mac.generate_random_mac(':')
assert re.match('([0-9A-F]{2}:){5}[0-9A-F]{2}', generated_mac) is not None
generated_mac = mac.generate_random_mac('-')
assert re.match('([0-9A-F]{2}-){5}[0-9A-F]{2}', generated_mac) is not None
def test_print_leading_zeros():
debug = False
mac = macs[100]
for i in range(100): # usually less than 10 is enough. TODO improve this.
generated_mac = mac.generate_random_mac(':').split(':')
if generated_mac[3][0] == '0' or \
generated_mac[4][0] == '0' or \
generated_mac[5][0] == '0':
if(debug):
print(f'Generated leading zeros at try: {i}')
return
raise Exception('Could not detect weather print leading zeros')
def test_find_mac_by_vendor_without_levenshtein():
vendor = 'intel'
macs = MAC._find_by_vendor_no_levenshtein(vendor)
assert len(macs) == 16
for mac in macs:
assert mac.vendor.lower() == vendor
def test_find_mac_by_vendor_using_levenshtein():
vendor = 'inel' # wanted intel but had typo, so user input 'inel'
MAC.set_levenshtein_max_dist_allowed(1)
macs = MAC._find_by_vendor_levenshtein(vendor)
# Intel was wanted but got 19 in total, 16 Intel plus Inkel, Indel and Inet.
expected_vendors = ['Inkel',
'Intel', 'Intel', 'Intel',
'Indel',
'Intel', 'Intel', 'Intel', 'Intel', 'Intel', 'Intel', 'Intel',
'Inet',
'Intel', 'Intel', 'Intel', 'Intel', 'Intel', 'Intel']
assert [m.vendor for m in macs] == expected_vendors
def main():
global macs
macs = test_load()
MAC.set_macs(macs)
assert macs is not None
test_find_mac_without_comments()
test_find_mac_with_comments()
test_find_mac_regardless_separator()
test_generate()
test_print_leading_zeros()
test_find_mac_by_vendor_without_levenshtein()
test_find_mac_by_vendor_using_levenshtein()
if __name__ == '__main__':
main()
sys.exit(0)