forked from wikimedia/pywikibot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests_tests.py
executable file
·111 lines (82 loc) · 3.02 KB
/
tests_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
"""Tests for the tests package."""
#
# (C) Pywikibot team, 2014-2023
#
# Distributed under the terms of the MIT license.
from __future__ import annotations
import unittest
from contextlib import suppress
from tests import utils
from tests.aspects import TestCase
class HttpServerProblemTestCase(TestCase):
"""Test HTTP status 502 causes this test class to be skipped."""
sites = {
'502': {
'hostname': 'http://httpbin.org/status/502',
}
}
def test_502(self):
"""Test that framework is skipping this test due to HTTP status 502."""
self.fail("The test framework should skip this test but it hasn't.")
class TestLengthAssertion(TestCase):
"""Test length assertion methods.
``@unittest.expectedFailure`` is used to test the failure of a test;
this is intentional. If the decorated test passes unexpectedly the
test will fail.
"""
net = False
seq1 = ('foo', 'bar', 'baz')
seq2 = 'foo'
def test_assert_is_empty(self):
"""Test assertIsEmpty method."""
self.assertIsEmpty([])
self.assertIsEmpty('')
@unittest.expectedFailure
def test_assert_is_empty_fail(self):
"""Test assertIsEmpty method failing."""
self.assertIsEmpty(self.seq1)
self.assertIsEmpty(self.seq2)
def test_assert_is_not_empty(self):
"""Test assertIsNotEmpty method."""
self.assertIsNotEmpty(self.seq1)
self.assertIsNotEmpty(self.seq2)
@unittest.expectedFailure
def test_assert_is_not_empty_fail(self):
"""Test that assertIsNotEmpty method may fail."""
self.assertIsNotEmpty([])
self.assertIsNotEmpty('')
def test_assert_length(self):
"""Test assertLength method."""
self.assertLength([], 0)
self.assertLength(self.seq1, 3)
self.assertLength(self.seq1, self.seq2)
@unittest.expectedFailure
def test_assert_length_fail(self):
"""Test that assertLength method is failing."""
self.assertLength([], 1)
self.assertLength(self.seq1, 0)
self.assertLength(None, self.seq)
class UtilsTests(TestCase):
"""Tests for tests.utils."""
net = False
pattern = 'Hello World'
def test_fixed_generator(self):
"""Test utils.fixed_generator."""
gen = utils.fixed_generator(self.pattern)
self.assertEqual(list(gen(1, 'foo', bar='baz')), list(self.pattern))
def test_entered_loop(self):
"""Test utils.entered_loop."""
self.assertTrue(utils.entered_loop(self.pattern))
self.assertFalse(utils.entered_loop(''))
@utils.expected_failure_if(True)
def test_expected_failure_true(self):
"""Test expected_failure_if decorator if condition is True."""
self.assertTrue(False)
@utils.expected_failure_if(False)
def test_expected_failure_false(self):
"""Test expected_failure_if decorator if condition is False."""
self.assertTrue(True)
if __name__ == '__main__':
with suppress(SystemExit):
unittest.main()