jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] flow_edit_tests: use contextmanager to setup/restore subtests

Change-Id: I47e4cd45d1d607a7df9734a4192c9564b7d7ec52
---
M tests/flow_edit_tests.py
1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index 0b06191..43e62d9 100644
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -5,7 +5,7 @@
#
# Distributed under the terms of the MIT license.
#
-from contextlib import suppress
+from contextlib import contextmanager, suppress

from pywikibot.exceptions import LockedPage
from pywikibot.flow import Board, Topic, Post
@@ -221,6 +221,20 @@
self.topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh')
self.post = Post(self.topic, 'sq1qvoig1az8w7cd')

+ @contextmanager
+ def restored(self, flow):
+ """Setup and restore test."""
+ # Setup
+ if flow.is_moderated:
+ flow.restore(MODERATION_REASON)
+ self.assertFalse(flow.is_moderated)
+ try:
+ yield flow
+ finally:
+ # Restore
+ flow.restore(MODERATION_REASON)
+ self.assertFalse(flow.is_moderated)
+

class TestFlowHide(FlowTests):

@@ -229,17 +243,11 @@
def test_hide(self):
"""Hide and restore a test topic and post."""
for flow in (self.topic, self.post):
- with self.subTest(flow=flow.__class__.__name__):
- # Setup
- if flow.is_moderated:
- flow.restore(MODERATION_REASON)
- self.assertFalse(flow.is_moderated)
+ with self.subTest(flow=flow.__class__.__name__), \
+ self.restored(flow):
# Hide
flow.hide(MODERATION_REASON)
self.assertTrue(flow.is_moderated)
- # Restore
- flow.restore(MODERATION_REASON)
- self.assertFalse(flow.is_moderated)


class TestFlowSysop(FlowTests):
@@ -251,32 +259,20 @@
def test_delete(self):
"""Delete and restore a test topic and post."""
for flow in (self.topic, self.post):
- with self.subTest(flow=flow.__class__.__name__):
- # Setup
- if flow.is_moderated:
- flow.restore(MODERATION_REASON)
- self.assertFalse(flow.is_moderated)
+ with self.subTest(flow=flow.__class__.__name__), \
+ self.restored(flow):
# Delete
flow.delete_mod(MODERATION_REASON)
self.assertTrue(flow.is_moderated)
- # Restore
- flow.restore(MODERATION_REASON)
- self.assertFalse(flow.is_moderated)

def test_suppress(self):
"""Suppress and restore a test topic and post."""
for flow in (self.topic, self.post):
- with self.subTest(flow=flow.__class__.__name__):
- # Setup
- if flow.is_moderated:
- flow.restore(MODERATION_REASON)
- self.assertFalse(flow.is_moderated)
+ with self.subTest(flow=flow.__class__.__name__), \
+ self.restored(flow):
# Suppress
flow.suppress(MODERATION_REASON)
self.assertTrue(flow.is_moderated)
- # Restore
- flow.restore(MODERATION_REASON)
- self.assertFalse(flow.is_moderated)


if __name__ == '__main__': # pragma: no cover

To view, visit change 649572. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I47e4cd45d1d607a7df9734a4192c9564b7d7ec52
Gerrit-Change-Number: 649572
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged