forked from OrneLibrary/DeepOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepOneTest.py
71 lines (54 loc) · 1.93 KB
/
deepOneTest.py
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
import pytest
import tempfile
import os
from deepOne import expand, process_file
def test_expand_cidr():
print("\nTesting CIDR expansion")
result = expand("192.168.1.0/30")
assert result == ["192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3"]
print("CIDR expansion test passed")
def test_expand_last_octet():
print("\nTesting last octet expansion")
result = expand("192.168.1.1-3")
assert result == ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
print("Last octet expansion test passed")
def test_expand_all_octets():
print("\nTesting full IP range expansion")
result = expand("192.168.1.254-192.168.2.2")
assert result == [
"192.168.1.254",
"192.168.1.255",
"192.168.2.0",
"192.168.2.1",
"192.168.2.2",
]
print("Full IP range expansion test passed")
def test_expand_single_ip():
print("\nTesting single IP expansion")
result = expand("192.168.1.1")
assert result == ["192.168.1.1"]
print("Single IP expansion test passed")
def test_expand_invalid_ip():
print("\nTesting invalid IP handling")
result = expand("invalid_ip")
assert result == []
print("Invalid IP handling test passed")
def test_process_file():
print("\nTesting file processing")
with tempfile.NamedTemporaryFile(
mode="w+", delete=False
) as input_file, tempfile.NamedTemporaryFile(
mode="w+", delete=False
) as output_file:
input_file.write("192.168.1.0/31\n")
input_file.write("192.168.1.2-3\n")
input_file.flush()
exclude_set = set(["192.168.1.1"])
process_file(input_file.name, exclude_set, output_file.name)
output_file.seek(0)
result = output_file.read().splitlines()
assert result == ["192.168.1.0", "192.168.1.2", "192.168.1.3"]
print("File processing test passed")
# Clean up temporary files
os.unlink(input_file.name)
os.unlink(output_file.name)