mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Convert IPAddress to use Pythonmodule ipaddress (#8072)
This commit is contained in:
		| @@ -1,12 +1,12 @@ | ||||
| import pytest | ||||
| import string | ||||
|  | ||||
| from hypothesis import given, example | ||||
| from hypothesis.strategies import one_of, text, integers, builds | ||||
| from hypothesis import example, given | ||||
| from hypothesis.strategies import builds, integers, ip_addresses, one_of, text | ||||
| import pytest | ||||
|  | ||||
| from esphome import config_validation | ||||
| from esphome.config_validation import Invalid | ||||
| from esphome.core import CORE, Lambda, HexInt | ||||
| from esphome.core import CORE, HexInt, Lambda | ||||
|  | ||||
|  | ||||
| def test_check_not_templatable__invalid(): | ||||
| @@ -145,6 +145,28 @@ def test_boolean__invalid(value): | ||||
|         config_validation.boolean(value) | ||||
|  | ||||
|  | ||||
| @given(value=ip_addresses(v=4).map(str)) | ||||
| def test_ipv4__valid(value): | ||||
|     config_validation.ipv4address(value) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("127.0.0", "localhost", "")) | ||||
| def test_ipv4__invalid(value): | ||||
|     with pytest.raises(Invalid, match="is not a valid IPv4 address"): | ||||
|         config_validation.ipv4address(value) | ||||
|  | ||||
|  | ||||
| @given(value=ip_addresses(v=6).map(str)) | ||||
| def test_ipv6__valid(value): | ||||
|     config_validation.ipaddress(value) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("127.0.0", "localhost", "", "2001:db8::2::3")) | ||||
| def test_ipv6__invalid(value): | ||||
|     with pytest.raises(Invalid, match="is not a valid IP address"): | ||||
|         config_validation.ipaddress(value) | ||||
|  | ||||
|  | ||||
| # TODO: ensure_list | ||||
| @given(integers()) | ||||
| def hex_int__valid(value): | ||||
|   | ||||
| @@ -1,10 +1,8 @@ | ||||
| import pytest | ||||
|  | ||||
| from hypothesis import given | ||||
| from hypothesis.strategies import ip_addresses | ||||
| import pytest | ||||
| from strategies import mac_addr_strings | ||||
|  | ||||
| from esphome import core, const | ||||
| from esphome import const, core | ||||
|  | ||||
|  | ||||
| class TestHexInt: | ||||
| @@ -26,25 +24,6 @@ class TestHexInt: | ||||
|         assert actual == expected | ||||
|  | ||||
|  | ||||
| class TestIPAddress: | ||||
|     @given(value=ip_addresses(v=4).map(str)) | ||||
|     def test_init__valid(self, value): | ||||
|         core.IPAddress(*value.split(".")) | ||||
|  | ||||
|     @pytest.mark.parametrize("value", ("127.0.0", "localhost", "")) | ||||
|     def test_init__invalid(self, value): | ||||
|         with pytest.raises(ValueError, match="IPAddress must consist of 4 items"): | ||||
|             core.IPAddress(*value.split(".")) | ||||
|  | ||||
|     @given(value=ip_addresses(v=4).map(str)) | ||||
|     def test_str(self, value): | ||||
|         target = core.IPAddress(*value.split(".")) | ||||
|  | ||||
|         actual = str(target) | ||||
|  | ||||
|         assert actual == value | ||||
|  | ||||
|  | ||||
| class TestMACAddress: | ||||
|     @given(value=mac_addr_strings()) | ||||
|     def test_init__valid(self, value): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user