Skip to content

Commit bdbd382

Browse files
committed
split tests even if they could end up duplicated
1 parent b6949dd commit bdbd382

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

Lib/test/test_pyexpat.py

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -868,24 +868,10 @@ def set_maximum_amplification(self, parser, max_factor):
868868
raise NotImplementedError
869869

870870
def test_set_maximum_amplification_reached(self):
871-
parser = expat.ParserCreate()
872-
# Unconditionally enable maximum activation factor.
873-
self.set_activation_threshold(parser, 0)
874-
# Choose a max amplification factor expected to always be exceeded.
875-
self.assertIsNone(self.set_maximum_amplification(parser, 1.0))
876-
# Craft a payload for which the peak amplification factor is > 1.0.
877-
payload = self.exponential_expansion_payload(1, 2)
878-
self.assert_active_protection(parser.Parse, payload, True)
871+
raise NotImplementedError
879872

880873
def test_set_maximum_amplification_ignored(self):
881-
parser = expat.ParserCreate()
882-
# Unconditionally enable maximum activation factor.
883-
self.set_activation_threshold(parser, 0)
884-
# Choose a max amplification factor expected to never be exceeded.
885-
self.assertIsNone(self.set_maximum_amplification(parser, 1e4))
886-
# Craft a payload for which the peak amplification factor is < 1e4.
887-
payload = self.exponential_expansion_payload(1, 2)
888-
self.assertIsNotNone(parser.Parse(payload, True))
874+
raise NotImplementedError
889875

890876
def test_set_maximum_amplification_infinity(self):
891877
inf = float('inf') # an 'inf' threshold is allowed by Expat
@@ -914,24 +900,10 @@ def test_set_maximum_amplification_fail_for_subparser(self):
914900
self.assert_root_parser_failure(setter, 123.45)
915901

916902
def test_set_attack_protection_threshold_reached(self):
917-
parser = expat.ParserCreate()
918-
# Choose a threshold expected to be always reached.
919-
self.set_activation_threshold(parser, 3)
920-
# Check that the threshold is reached by choosing a small factor
921-
# and a payload whose peak amplification factor exceeds it.
922-
self.assertIsNone(self.set_maximum_amplification(parser, 1.0))
923-
payload = self.exponential_expansion_payload(10, 4)
924-
self.assert_active_protection(parser.Parse, payload, True)
903+
raise NotImplementedError
925904

926905
def test_set_attack_protection_threshold_ignored(self):
927-
parser = expat.ParserCreate()
928-
# Choose a threshold expected to be never reached.
929-
self.set_activation_threshold(parser, pow(10, 5))
930-
# Check that the threshold is reached by choosing a small factor
931-
# and a payload whose peak amplification factor exceeds it.
932-
self.assertIsNone(self.set_maximum_amplification(parser, 1.0))
933-
payload = self.exponential_expansion_payload(10, 4)
934-
self.assertIsNotNone(parser.Parse(payload, True))
906+
raise NotImplementedError
935907

936908
def test_set_attack_protection_threshold_arg_invalid_type(self):
937909
parser = expat.ParserCreate()
@@ -974,6 +946,46 @@ def set_maximum_amplification(self, parser, max_factor):
974946
def set_activation_threshold(self, parser, threshold):
975947
return parser.SetAllocTrackerActivationThreshold(threshold)
976948

949+
def test_set_maximum_amplification_reached(self):
950+
parser = expat.ParserCreate()
951+
# Unconditionally enable maximum activation factor.
952+
self.set_activation_threshold(parser, 0)
953+
# Choose a max amplification factor expected to always be exceeded.
954+
self.assertIsNone(self.set_maximum_amplification(parser, 1.0))
955+
# Craft a payload for which the peak amplification factor is > 1.0.
956+
payload = self.exponential_expansion_payload(1, 2)
957+
self.assert_active_protection(parser.Parse, payload, True)
958+
959+
def test_set_maximum_amplification_ignored(self):
960+
parser = expat.ParserCreate()
961+
# Unconditionally enable maximum activation factor.
962+
self.set_activation_threshold(parser, 0)
963+
# Choose a max amplification factor expected to never be exceeded.
964+
self.assertIsNone(self.set_maximum_amplification(parser, 1e4))
965+
# Craft a payload for which the peak amplification factor is < 1e4.
966+
payload = self.exponential_expansion_payload(1, 2)
967+
self.assertIsNotNone(parser.Parse(payload, True))
968+
969+
def test_set_attack_protection_threshold_reached(self):
970+
parser = expat.ParserCreate()
971+
# Choose a threshold expected to be always reached.
972+
self.set_activation_threshold(parser, 3)
973+
# Check that the threshold is reached by choosing a small factor
974+
# and a payload whose peak amplification factor exceeds it.
975+
self.assertIsNone(self.set_maximum_amplification(parser, 1.0))
976+
payload = self.exponential_expansion_payload(10, 4)
977+
self.assert_active_protection(parser.Parse, payload, True)
978+
979+
def test_set_attack_protection_threshold_ignored(self):
980+
parser = expat.ParserCreate()
981+
# Choose a threshold expected to be never reached.
982+
self.set_activation_threshold(parser, pow(10, 5))
983+
# Check that the threshold is reached by choosing a small factor
984+
# and a payload whose peak amplification factor exceeds it.
985+
self.assertIsNone(self.set_maximum_amplification(parser, 1.0))
986+
payload = self.exponential_expansion_payload(10, 4)
987+
self.assertIsNotNone(parser.Parse(payload, True))
988+
977989

978990
if __name__ == "__main__":
979991
unittest.main()

0 commit comments

Comments
 (0)