mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-07-01 02:36:52 +00:00
Sorting and update of imports && deletion of Python2 related logic
This patch is related to https://github.com/StevenBlack/hosts/issues/729
This commit is contained in:
@@ -33,7 +33,6 @@ from updateHostsFile import (Colors, colorize, display_exclusion_options,
|
||||
|
||||
unicode = str
|
||||
|
||||
|
||||
# Test Helper Objects
|
||||
class Base(unittest.TestCase):
|
||||
|
||||
@@ -43,7 +42,7 @@ class Base(unittest.TestCase):
|
||||
|
||||
@property
|
||||
def sep(self):
|
||||
return os.sep
|
||||
return "\\" if sys.platform == "win32" else "/"
|
||||
|
||||
def assert_called_once(self, mock_method):
|
||||
self.assertEqual(mock_method.call_count, 1)
|
||||
@@ -106,7 +105,7 @@ class TestGetDefaults(Base):
|
||||
"readmedata": {},
|
||||
"readmedatafilename": ("foo" + self.sep +
|
||||
"readmeData.json"),
|
||||
"exclusionpattern": r"([a-zA-Z\d-]+\.){0,}",
|
||||
"exclusionpattern": "([a-zA-Z\d-]+\.){0,}",
|
||||
"exclusionregexs": [],
|
||||
"exclusions": [],
|
||||
"commonexclusions": ["hulu.com"],
|
||||
@@ -244,6 +243,7 @@ class TestPromptForUpdate(BaseStdout, BaseMockDir):
|
||||
|
||||
def tearDown(self):
|
||||
BaseStdout.tearDown(self)
|
||||
# BaseStdout.tearDown(self)
|
||||
|
||||
|
||||
class TestPromptForExclusions(BaseStdout):
|
||||
@@ -455,7 +455,7 @@ class TestGatherCustomExclusions(BaseStdout):
|
||||
|
||||
# Can only test in the invalid domain case
|
||||
# because of the settings global variable.
|
||||
@mock.patch("updateHostsFile.input", side_effect=["foo", "no"])
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=["foo", "no"])
|
||||
@mock.patch("updateHostsFile.is_valid_domain_format", return_value=False)
|
||||
def test_basic(self, *_):
|
||||
gather_custom_exclusions("foo", [])
|
||||
@@ -464,7 +464,8 @@ class TestGatherCustomExclusions(BaseStdout):
|
||||
output = sys.stdout.getvalue()
|
||||
self.assertIn(expected, output)
|
||||
|
||||
@mock.patch("updateHostsFile.input", side_effect=["foo", "yes", "bar", "no"])
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=["foo", "yes",
|
||||
"bar", "no"])
|
||||
@mock.patch("updateHostsFile.is_valid_domain_format", return_value=False)
|
||||
def test_multiple(self, *_):
|
||||
gather_custom_exclusions("foo", [])
|
||||
@@ -491,7 +492,7 @@ class TestExcludeDomain(Base):
|
||||
exp_count = 0
|
||||
expected_regexes = []
|
||||
exclusion_regexes = []
|
||||
exclusion_pattern = r"[a-z]\."
|
||||
exclusion_pattern = "[a-z]\."
|
||||
|
||||
for domain in ["google.com", "hulu.com", "adaway.org"]:
|
||||
self.assertEqual(len(exclusion_regexes), exp_count)
|
||||
@@ -517,7 +518,7 @@ class TestMatchesExclusions(Base):
|
||||
self.assertFalse(matches_exclusions(domain, exclusion_regexes))
|
||||
|
||||
def test_no_match_list(self):
|
||||
exclusion_regexes = [r".*\.org", r".*\.edu"]
|
||||
exclusion_regexes = [".*\.org", ".*\.edu"]
|
||||
exclusion_regexes = [re.compile(regex) for regex in exclusion_regexes]
|
||||
|
||||
for domain in ["1.2.3.4 localhost", "5.6.7.8 hulu.com",
|
||||
@@ -525,7 +526,7 @@ class TestMatchesExclusions(Base):
|
||||
self.assertFalse(matches_exclusions(domain, exclusion_regexes))
|
||||
|
||||
def test_match_list(self):
|
||||
exclusion_regexes = [r".*\.com", r".*\.org", r".*\.edu"]
|
||||
exclusion_regexes = [".*\.com", ".*\.org", ".*\.edu"]
|
||||
exclusion_regexes = [re.compile(regex) for regex in exclusion_regexes]
|
||||
|
||||
for domain in ["5.6.7.8 hulu.com", "9.1.2.3 yahoo.com",
|
||||
@@ -1087,7 +1088,7 @@ class TestMoveHostsFile(BaseStdout):
|
||||
expected = ("Automatically moving the hosts "
|
||||
"file in place is not yet supported.\n"
|
||||
"Please move the generated file to "
|
||||
r"%SystemRoot%\system32\drivers\etc\hosts")
|
||||
"%SystemRoot%\system32\drivers\etc\hosts")
|
||||
output = sys.stdout.getvalue()
|
||||
self.assertIn(expected, output)
|
||||
|
||||
@@ -1587,7 +1588,7 @@ class TestQueryYesOrNo(BaseStdout):
|
||||
for invalid_default in ["foo", "bar", "baz", 1, 2, 3]:
|
||||
self.assertRaises(ValueError, query_yes_no, "?", invalid_default)
|
||||
|
||||
@mock.patch("updateHostsFile.input", side_effect=["yes"] * 3)
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=["yes"] * 3)
|
||||
def test_valid_default(self, _):
|
||||
for valid_default, expected in [(None, "[y/n]"), ("yes", "[Y/n]"),
|
||||
("no", "[y/N]")]:
|
||||
@@ -1598,7 +1599,7 @@ class TestQueryYesOrNo(BaseStdout):
|
||||
|
||||
self.assertIn(expected, output)
|
||||
|
||||
@mock.patch("updateHostsFile.input", side_effect=([""] * 2))
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=([""] * 2))
|
||||
def test_use_valid_default(self, _):
|
||||
for valid_default in ["yes", "no"]:
|
||||
expected = (valid_default == "yes")
|
||||
@@ -1606,15 +1607,19 @@ class TestQueryYesOrNo(BaseStdout):
|
||||
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
@mock.patch("updateHostsFile.input", side_effect=["no", "NO", "N", "n", "No", "nO"])
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=["no", "NO", "N",
|
||||
"n", "No", "nO"])
|
||||
def test_valid_no(self, _):
|
||||
self.assertFalse(query_yes_no("?", None))
|
||||
|
||||
@mock.patch("updateHostsFile.input", side_effect=["yes", "YES", "Y", "yeS", "y", "YeS", "yES", "YEs"])
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=["yes", "YES", "Y",
|
||||
"yeS", "y", "YeS",
|
||||
"yES", "YEs"])
|
||||
def test_valid_yes(self, _):
|
||||
self.assertTrue(query_yes_no("?", None))
|
||||
|
||||
@mock.patch("updateHostsFile.input", side_effect=["foo", "yes", "foo", "no"])
|
||||
@mock.patch("updateHostsFile.raw_input", side_effect=["foo", "yes",
|
||||
"foo", "no"])
|
||||
def test_invalid_then_valid(self, _):
|
||||
expected = "Please respond with 'yes' or 'no'"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user