|
2 | 2 |
|
3 | 3 | import typing
|
4 | 4 | import unittest
|
| 5 | +import sys |
| 6 | +import os |
5 | 7 |
|
| 8 | +# Add the parent directory to the path to import kclvm_runtime |
| 9 | +parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 10 | +sys.path.append(parent_dir) |
6 | 11 | import kclvm_runtime
|
7 | 12 |
|
8 | 13 | # https://github.com/python/cpython/blob/main/Lib/test
|
9 |
| - |
10 | 14 | _Dylib = kclvm_runtime.KclvmRuntimeDylib()
|
11 | 15 |
|
12 | 16 |
|
13 | 17 | class kclx_Net:
|
14 | 18 | def __init__(self, dylib_=None):
|
15 | 19 | self.dylib = dylib_ if dylib_ else _Dylib
|
16 |
| - |
| 20 | + def is_global_unicast_IP(self, value: str) -> bool: |
| 21 | + return self.dylib.Invoke(f"net.is_global_unicast_IP", value) |
| 22 | + def is_link_local_multicast_IP(self, value: str) -> bool: |
| 23 | + return self.dylib.Invoke(f"net.is_link_local_multicast_IP", value) |
| 24 | + def is_interface_local_multicast_IP(self, value: str) -> bool: |
| 25 | + return self.dylib.Invoke(f"net.is_interface_local_multicast_IP", value) |
| 26 | + def is_multicast_IP(self, value: str) -> bool: |
| 27 | + return self.dylib.Invoke(f"net.is_multicast_IP", value) |
| 28 | + def is_loopback_IP(self, value: str) -> bool: |
| 29 | + return self.dylib.Invoke(f"net.is_loopback_IP", value) |
| 30 | + def is_link_local_unicast_IP(self, value: str) -> bool: |
| 31 | + return self.dylib.Invoke(f"net.is_link_local_unicast_IP", value) |
| 32 | + def is_unspecified_IP(self, value: str) -> bool: |
| 33 | + return self.dylib.Invoke(f"net.is_unspecified_IP", value) |
| 34 | + |
| 35 | + |
| 36 | +kclxnet = kclx_Net(_Dylib) |
17 | 37 |
|
18 | 38 | class BaseTest(unittest.TestCase):
|
19 |
| - def test_foo(self): |
20 |
| - self.assertTrue(True) |
21 |
| - |
| 39 | + def test_is_interface_local_multicast_IP(self): |
| 40 | + self.assertFalse(kclxnet.is_interface_local_multicast_IP("224.0.0.0")) |
| 41 | + self.assertTrue(kclxnet.is_interface_local_multicast_IP("ff11::1")) |
| 42 | + def test_is_link_local_multicast_IP(self): |
| 43 | + self.assertTrue(kclxnet.is_link_local_multicast_IP("ff12::1")) |
| 44 | + def test_is_global_unicast_IP(self): |
| 45 | + self.assertTrue(kclxnet.is_global_unicast_IP("2607:f8b0:4005:802::200e")) |
| 46 | + self.assertTrue(kclxnet.is_global_unicast_IP("64:ff9b::800:1")) |
| 47 | + self.assertTrue(kclxnet.is_global_unicast_IP("220.181.108.89")) |
| 48 | + def test_is_multicast_IP(self): |
| 49 | + self.assertTrue(kclxnet.is_multicast_IP("239.255.255.255")) |
| 50 | + def test_is_loopback_IP(self): |
| 51 | + self.assertTrue(kclxnet.is_loopback_IP("127.0.0.1")) |
| 52 | + def test_is_link_local_unicast_IP(self): |
| 53 | + self.assertTrue(kclxnet.is_link_local_unicast_IP("fe80::2012:1")) |
| 54 | + def test_is_unspecified_IP(self): |
| 55 | + self.assertTrue(kclxnet.is_unspecified_IP("0.0.0.0")) |
22 | 56 |
|
23 | 57 | if __name__ == "__main__":
|
24 | 58 | unittest.main()
|
0 commit comments