[Pywikibot-commits] [Gerrit] ...core[master]: [tests] Show user rights if UserRightsError is raised during tests

2024-04-23 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1023474?usp=email )

Change subject: [tests] Show user rights if UserRightsError is raised during 
tests
..

[tests] Show user rights if UserRightsError is raised during tests

Bug: T363190
Change-Id: Ic46e899e0fdc07ee34e1b2cd855e2fdd51835ead
---
M pywikibot/site/_decorators.py
M tests/site_decorators_tests.py
2 files changed, 48 insertions(+), 46 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/site/_decorators.py b/pywikibot/site/_decorators.py
index 3656e4e..6539355 100644
--- a/pywikibot/site/_decorators.py
+++ b/pywikibot/site/_decorators.py
@@ -1,15 +1,23 @@
 """Decorators used by site models."""
 #
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
 #
 # Distributed under the terms of the MIT license.
 #
 from __future__ import annotations

+import os
+from textwrap import fill
+
 from pywikibot.exceptions import UnknownExtensionError, UserRightsError
 from pywikibot.tools import MediaWikiVersion, manage_wrapping


+CLOSED_WIKI_MSG = (
+'Site {site} has been closed. Only steward can perform requested action.'
+)
+
+
 def must_be(group: str | None = None):
 """Decorator to require a certain user status when method is called.

@@ -24,15 +32,11 @@
 grp = kwargs.pop('as_group', group)
 if self.obsolete:
 if not self.has_group('steward'):
-raise UserRightsError(
-'Site {} has been closed. Only steward '
-'can perform requested action.'
-.format(self.sitename))
+raise UserRightsError(CLOSED_WIKI_MSG.format(site=self))

 elif not self.has_group(grp):
-raise UserRightsError('User "{}" is not part of the required '
-  'user group "{}"'
-  .format(self.user(), grp))
+raise UserRightsError(f'User "{self.user()}" is not part of '
+  f'the required user group "{grp}"')

 return fn(self, *args, **kwargs)

@@ -53,8 +57,8 @@
 def callee(self, *args, **kwargs):
 if not self.has_extension(extension):
 raise UnknownExtensionError(
-'Method "{}" is not implemented without the extension {}'
-.format(fn.__name__, extension))
+f'Method "{fn.__name__}" is not implemented without the '
+f'extension {extension}')
 return fn(self, *args, **kwargs)

 manage_wrapping(callee, fn)
@@ -74,15 +78,18 @@
 def callee(self, *args, **kwargs):
 if self.obsolete:
 if not self.has_group('steward'):
-raise UserRightsError(
-'Site {} has been closed. Only stewards '
-'can perform the requested action.'
-.format(self.sitename))
+raise UserRightsError(CLOSED_WIKI_MSG.format(site=self))

 elif right is not None and not self.has_right(right):
-raise UserRightsError('User "{}" does not have required '
-  'user right "{}"'
-  .format(self.user(), right))
+if os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1':
+rights = ' but:\n' + fill(
+str(sorted(self.userinfo['rights'])),
+width=76, break_on_hyphens=False)
+else:
+rights = '.'
+raise UserRightsError(
+f'User "{self.user()}" does not have required user right '
+f'"{right}"{rights}')
 return fn(self, *args, **kwargs)

 manage_wrapping(callee, fn)
@@ -102,9 +109,8 @@
 def callee(self, *args, **kwargs):
 if MediaWikiVersion(self.version()) < MediaWikiVersion(version):
 raise NotImplementedError(
-'Method or function "{}"\n'
-"isn't implemented in MediaWiki version < {}"
-.format(fn.__name__, version))
+f'Method or function "{fn.__name__}"\n'
+f"isn't implemented in MediaWiki version < {version}")
 return fn(self, *args, **kwargs)

 manage_wrapping(callee, fn)
diff --git a/tests/site_decorators_tests.py b/tests/site_decorators_tests.py
index a1e3c71..8256132 100755
--- a/tests/site_decorators_tests.py
+++ b/tests/site_decorators_tests.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """Tests against a fake Site object."""
 #
-# (C) Pywikibot team, 2012-2023
+# (C) Pywikibot team, 2012-2024
 #
 # Distributed under the terms of the 

[Pywikibot-commits] [Gerrit] ...core[master]: [tests} Update change-string-case-action to v6

2024-04-23 Thread Xqt (Code Review)
Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1023415?usp=email )

Change subject: [tests} Update change-string-case-action to v6
..

[tests} Update change-string-case-action to v6

Bug: T363160
Change-Id: Ie43604979f44b53c058bd08ec65864695948d940
---
M .github/workflows/oauth_tests-ci.yml
M .github/workflows/sysop_write_tests-ci.yml
2 files changed, 2 insertions(+), 2 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved




diff --git a/.github/workflows/oauth_tests-ci.yml 
b/.github/workflows/oauth_tests-ci.yml
index eb8a221..288bb6b 100644
--- a/.github/workflows/oauth_tests-ci.yml
+++ b/.github/workflows/oauth_tests-ci.yml
@@ -60,7 +60,7 @@
 - name: Get token name
   env:
 _oauth_token: OAUTH_TOKEN_${{ matrix.family }}_${{ matrix.code }}
-  uses: ASzc/change-string-case-action@v5
+  uses: ASzc/change-string-case-action@v6
   id: token
   with:
 string: ${{ env._oauth_token }}
diff --git a/.github/workflows/sysop_write_tests-ci.yml 
b/.github/workflows/sysop_write_tests-ci.yml
index 1986705..3828404 100644
--- a/.github/workflows/sysop_write_tests-ci.yml
+++ b/.github/workflows/sysop_write_tests-ci.yml
@@ -44,7 +44,7 @@
 - name: Get token name
   env:
 _oauth_token: OAUTH_TOKEN_${{ matrix.family }}_${{ matrix.code }}
-  uses: ASzc/change-string-case-action@v5
+  uses: ASzc/change-string-case-action@v6
   id: token
   with:
 string: ${{ env._oauth_token }}

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1023415?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie43604979f44b53c058bd08ec65864695948d940
Gerrit-Change-Number: 1023415
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt 
Gerrit-Reviewer: Xqt 
Gerrit-MessageType: merged
___
Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org
To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org


[Pywikibot-commits] [Gerrit] ...core[master]: [tests] Add two edit tests for WbTime

2024-04-23 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655524?usp=email )

Change subject: [tests] Add two edit tests for WbTime
..

[tests] Add two edit tests for WbTime

Adding the tests since I'm getting local "API error modification-failed: 
Malformed input" errors when using fromTimestr

Bug: T325860
Change-Id: I249e949c014455102b2f7c47da6a2bfb7d5eeaa3
---
M tests/wikibase_edit_tests.py
1 file changed, 36 insertions(+), 1 deletion(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index d2e9fc5..3d9bb47 100755
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -6,7 +6,7 @@
 class in edit_failiure_tests.py
 """
 #
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2024
 #
 # Distributed under the terms of the MIT license.
 #
@@ -430,6 +430,41 @@
 claim = item.claims['P88936'][0]
 self.assertEqual(claim.getTarget(), target)

+def test_WbTime_edit_simple(self):
+"""Attempt adding a WbTime claim with valid input."""
+testsite = self.get_repo()
+item = self._clean_item(testsite, 'P66')
+
+# set new claim
+claim = pywikibot.page.Claim(
+testsite, 'P66', datatype='time')
+target = pywikibot.WbTime(year=2012)
+claim.setTarget(target)
+item.addClaim(claim)
+
+# confirm new claim
+item.get(force=True)
+claim = item.claims['P66'][0]
+self.assertEqual(claim.getTarget(), target)
+
+@unittest.expectedFailure  # T325860
+def test_WbTime_edit_fromTimestr(self):
+"""Attempt adding a WbTime claim with valid input."""
+testsite = self.get_repo()
+item = self._clean_item(testsite, 'P66')
+
+# set new claim
+claim = pywikibot.page.Claim(
+testsite, 'P66', datatype='time')
+target = pywikibot.WbTime.fromTimestr('+0002010-01-01T12:43:01Z')
+claim.setTarget(target)
+item.addClaim(claim)
+
+# confirm new claim
+item.get(force=True)
+claim = item.claims['P66'][0]
+self.assertEqual(claim.getTarget(), target)
+

 class TestWikibaseRemoveQualifier(WikibaseTestCase):


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655524?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I249e949c014455102b2f7c47da6a2bfb7d5eeaa3
Gerrit-Change-Number: 655524
Gerrit-PatchSet: 5
Gerrit-Owner: Lokal Profil 
Gerrit-Reviewer: Xqt 
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
___
Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org
To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org