From: funilrys Date: Sun, 4 Mar 2018 10:18:50 +0000 (+0100) Subject: Introduction of more tests cases X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=318389b08f122ca6863e12f11f9771a3cd3bd09d;p=stevenblack-hosts.git Introduction of more tests cases Please note that this patch introduce more tests cases in order to avoid future issue when calling `domains_to_idna()` --- diff --git a/testUpdateHostsFile.py b/testUpdateHostsFile.py index b4f4bfdca..d6d901aa7 100644 --- a/testUpdateHostsFile.py +++ b/testUpdateHostsFile.py @@ -1407,7 +1407,27 @@ class DomainToIDNA(Base): self.assertEqual(actual, expected) - def test_single_line_with_comment_at_the_end(self): + def test_multiple_space_as_separator(self): + # Test with multiple space as separator. + for i in range(len(self.domains)): + data = (b"0.0.0.0 " + self.domains[i]).decode('utf-8') + expected = "0.0.0.0 " + self.expected_domains[i] + + actual = domain_to_idna(data) + + self.assertEqual(actual, expected) + + def test_multiple_tabs_as_separator(self): + # Test with multiple tabls as separator. + for i in range(len(self.domains)): + data = (b"0.0.0.0\t\t\t\t\t\t" + self.domains[i]).decode('utf-8') + expected = "0.0.0.0\t\t\t\t\t\t" + self.expected_domains[i] + + actual = domain_to_idna(data) + + self.assertEqual(actual, expected) + + def test_line_with_comment_at_the_end(self): # Test with a space as separator. for i in range(len(self.domains)): data = (b"0.0.0.0 " + self.domains[i] + b" # Hello World") \ @@ -1429,7 +1449,56 @@ class DomainToIDNA(Base): self.assertEqual(actual, expected) - def test_single_line_without_prefix(self): + # Test with tabulation as separator of domain and comment. + for i in range(len(self.domains)): + data = (b"0.0.0.0\t" + self.domains[i] + b"\t # Hello World") \ + .decode('utf-8') + expected = "0.0.0.0\t" + self.expected_domains[i] + \ + "\t # Hello World" + + actual = domain_to_idna(data) + + self.assertEqual(actual, expected) + + # Test with space as separator of domain and tabulation as separator + # of comments. + for i in range(len(self.domains)): + data = (b"0.0.0.0 " + self.domains[i] + b" \t # Hello World") \ + .decode('utf-8') + expected = "0.0.0.0 " + self.expected_domains[i] + \ + " \t # Hello World" + + actual = domain_to_idna(data) + + self.assertEqual(actual, expected) + + # Test with multiple space as seprator of domain and space and + # tabulation as separator or comments. + for i in range(len(self.domains)): + data = (b"0.0.0.0 " + self.domains[i] + b" \t # Hello World") \ + .decode('utf-8') + expected = "0.0.0.0 " + self.expected_domains[i] + \ + " \t # Hello World" + + actual = domain_to_idna(data) + + self.assertEqual(actual, expected) + + # Test with multiple tabulations as seprator of domain and space and + # tabulation as separator or comments. + for i in range(len(self.domains)): + data = (b"0.0.0.0\t\t\t" + + self.domains[i] + + b" \t # Hello World") \ + .decode('utf-8') + expected = "0.0.0.0\t\t\t" + self.expected_domains[i] + \ + " \t # Hello World" + + actual = domain_to_idna(data) + + self.assertEqual(actual, expected) + + def test_line_without_prefix(self): for i in range(len(self.domains)): data = self.domains[i].decode('utf-8') expected = self.expected_domains[i]