Clockery has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/399399 )
Change subject: Replace assertRaises with assertRaisesRegex in flow_tests.py
......................................................................
Replace assertRaises with assertRaisesRegex in flow_tests.py
assertRaisesRegex has an extra parameter to check the exception raised
against a provided string, to ensure the precise exception expected is
raised.
Bug: T154281
Change-Id: I05c6c82f157b23b554248f32ff096ae2ecdb439a
---
M tests/flow_tests.py
1 file changed, 26 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/99/399399/1
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
index dfc87f8..8446bd5 100644
--- a/tests/flow_tests.py
+++ b/tests/flow_tests.py
@@ -19,6 +19,16 @@
BasePageLoadRevisionsCachingTestBase,
)
+# variables to check regex used in assertRaisesRegex
+
+illegal_post_data_error = 'Illegal post data.*'
+topic_must_exist_error = 'Topic must exist:.*'
+current_post_revision_error = 'Current revision of postnot found in supplied
data.*'
+pywiki_flow_object_error = 'board must be a pywikibot.flow.Board object.'
+topic_uuid_string_error = 'Topic/root UUID must be a string.'
+page_topic_object_error = 'Page must be a Topic object'
+post_uuid_string_error = 'Post UUID must be a string'
+post_not_found_error = 'Post not found in supplied data.*'
class TestMediaWikiFlowSandbox(TestCase):
@@ -168,18 +178,18 @@
real_topic = Topic(self.site, 'Topic:Slbktgav46omarsd')
fake_topic = Topic(self.site, 'Topic:Abcdefgh12345678')
# Topic.from_topiclist_data
- self.assertRaises(TypeError, Topic.from_topiclist_data, self.site, '',
{})
- self.assertRaises(TypeError, Topic.from_topiclist_data, board, 521, {})
- self.assertRaises(TypeError, Topic.from_topiclist_data, board,
+ self.assertRaisesRegex(TypeError, pywiki_flow_object_error,
Topic.from_topiclist_data, self.site, '', {})
+ self.assertRaisesRegex(TypeError, topic_uuid_string_error,
Topic.from_topiclist_data, board, 521, {})
+ self.assertRaisesRegex(TypeError, illegal_post_data_error,
Topic.from_topiclist_data, board,
'slbktgav46omarsd', [0, 1, 2])
- self.assertRaises(NoPage, Topic.from_topiclist_data, board,
+ self.assertRaisesRegex(NoPage, topic_must_exist_error,
Topic.from_topiclist_data, board,
'abc', {'stuff': 'blah'})
# Post.fromJSON
- self.assertRaises(TypeError, Post.fromJSON, board, 'abc', {})
- self.assertRaises(TypeError, Post.fromJSON, real_topic, 1234, {})
- self.assertRaises(TypeError, Post.fromJSON, real_topic, 'abc', [])
- self.assertRaises(NoPage, Post.fromJSON, fake_topic, 'abc',
+ self.assertRaisesRegex(TypeError, page_topic_object_error,
Post.fromJSON, board, 'abc', {})
+ self.assertRaisesRegex(TypeError, post_uuid_string_error,
Post.fromJSON, real_topic, 1234, {})
+ self.assertRaisesRegex(TypeError, illegal_post_data_error,
Post.fromJSON, real_topic, 'abc', [])
+ self.assertRaisesRegex(NoPage, topic_must_exist_error, Post.fromJSON,
fake_topic, 'abc',
{'posts': [], 'revisions': []})
def test_invalid_data(self):
@@ -187,27 +197,27 @@
board = Board(self.site, 'Talk:Pywikibot test')
real_topic = Topic(self.site, 'Topic:Slbktgav46omarsd')
# Topic.from_topiclist_data
- self.assertRaises(ValueError, Topic.from_topiclist_data,
+ self.assertRaisesRegex(ValueError, illegal_post_data_error,
Topic.from_topiclist_data,
board, 'slbktgav46omarsd', {'stuff': 'blah'})
- self.assertRaises(ValueError, Topic.from_topiclist_data,
+ self.assertRaisesRegex(ValueError, post_not_found_error,
Topic.from_topiclist_data,
board, 'slbktgav46omarsd',
{'posts': [], 'revisions': []})
- self.assertRaises(ValueError, Topic.from_topiclist_data, board,
+ self.assertRaisesRegex(ValueError, current_post_revision_error,
Topic.from_topiclist_data, board,
'slbktgav46omarsd',
{'posts': {'slbktgav46omarsd': ['123']},
'revisions': {'456': []}})
- self.assertRaises(AssertionError, Topic.from_topiclist_data, board,
+ self.assertRaisesRegex(AssertionError, '', Topic.from_topiclist_data,
board,
'slbktgav46omarsd',
{'posts': {'slbktgav46omarsd': ['123']},
'revisions': {'123': {'content': 789}}})
# Post.fromJSON
- self.assertRaises(ValueError, Post.fromJSON, real_topic, 'abc', {})
- self.assertRaises(ValueError, Post.fromJSON, real_topic, 'abc',
+ self.assertRaisesRegex(ValueError, illegal_post_data_error,
Post.fromJSON, real_topic, 'abc', {})
+ self.assertRaisesRegex(ValueError, illegal_post_data_error,
Post.fromJSON, real_topic, 'abc',
{'stuff': 'blah'})
- self.assertRaises(ValueError, Post.fromJSON, real_topic, 'abc',
+ self.assertRaisesRegex(ValueError, current_post_revision_error,
Post.fromJSON, real_topic, 'abc',
{'posts': {'abc': ['123']},
'revisions': {'456': []}})
- self.assertRaises(AssertionError, Post.fromJSON, real_topic, 'abc',
+ self.assertRaisesRegex(AssertionError, '', Post.fromJSON, real_topic,
'abc',
{'posts': {'abc': ['123']},
'revisions': {'123': {'content': 789}}})
--
To view, visit https://gerrit.wikimedia.org/r/399399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I05c6c82f157b23b554248f32ff096ae2ecdb439a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Clockery <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits