jenkins-bot has submitted this change and it was merged. Change subject: [FIX] fixes: Allow replacing the variable ......................................................................
[FIX] fixes: Allow replacing the variable In 3ac1880 loading the fixes was moved inside a function which replaced the module global entries with the function global entries. And when a fixes file was replacing the variable it wasn't propagated to the module so that in the end it didn't edit anything. Bug: T112102 Change-Id: Ic0dd78eec8c38b1a4733e49866d20e3d677339f5 --- M pywikibot/fixes.py A tests/data/set-fixes.py A tests/fixes_tests.py 3 files changed, 62 insertions(+), 1 deletion(-) Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/fixes.py b/pywikibot/fixes.py index 67cc716..568863e 100644 --- a/pywikibot/fixes.py +++ b/pywikibot/fixes.py @@ -643,7 +643,7 @@ if os.path.exists(filename): # load binary, to let compile decode it according to the file header with open(filename, 'rb') as f: - exec(compile(f.read(), filename, 'exec')) + exec(compile(f.read(), filename, 'exec'), globals()) return True else: return False diff --git a/tests/data/set-fixes.py b/tests/data/set-fixes.py new file mode 100644 index 0000000..ad6dd9c --- /dev/null +++ b/tests/data/set-fixes.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +"""Fixes implementation which overwrites the variable.""" +from __future__ import unicode_literals + +# Just kill the old value suffices +fixes = {} diff --git a/tests/fixes_tests.py b/tests/fixes_tests.py new file mode 100644 index 0000000..b22e69c --- /dev/null +++ b/tests/fixes_tests.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +"""Tests for fixes module.""" +# +# (C) Pywikibot team, 2015 +# +# Distributed under the terms of the MIT license. +# +from __future__ import unicode_literals + +__version__ = '$Id$' +# +import os + +from pywikibot import fixes + +from tests import unittest, _data_dir +from tests.aspects import TestCase + + +class TestFixes(TestCase): + + """Test the fixes module.""" + + net = False + + def setUp(self): + """Backup the current fixes.""" + super(TestFixes, self).setUp() + self._old_fixes = fixes.fixes + + def tearDown(self): + """Recover the current fixes.""" + fixes.fixes = self._old_fixes + super(TestFixes, self).tearDown() + + def test_overwrite_value(self): + """Test loading a fix file overwriting the fixes.""" + fixes.fixes = {} + old_fixes = fixes.fixes + fixes._load_file(os.path.join(_data_dir, 'set-fixes.py')) + self.assertIsNot(fixes.fixes, old_fixes) + + def test_update_value(self): + """Test loading a fix file changing the fixes.""" + fixes.fixes = {} + old_fixes = fixes.fixes + fixes._load_file(os.path.join(_data_dir, 'fixes.py')) + self.assertIs(fixes.fixes, old_fixes) + + +if __name__ == '__main__': + try: + unittest.main() + except SystemExit: + pass -- To view, visit https://gerrit.wikimedia.org/r/237999 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic0dd78eec8c38b1a4733e49866d20e3d677339f5 Gerrit-PatchSet: 3 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits