[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Replace assertRaises with assertRaisesRegex in isbn_tests.py

2018-01-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/404085 )

Change subject: Replace assertRaises with assertRaisesRegex in isbn_tests.py
..


Replace assertRaises with assertRaisesRegex in isbn_tests.py

assertRaises is not as good of a test as asserRaisesRegex.
The latter has an extra parameter to match the exception message,
allowing more more precision when checking an error.

Bug: T154281
Change-Id: Iaab3472bbae926caf5d68239b3828b5691ee38b9
---
M tests/isbn_tests.py
1 file changed, 53 insertions(+), 15 deletions(-)

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



diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index df00417..ae867d2 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -34,10 +34,29 @@
 else:
 AnyIsbnValidationException = IsbnExc
 
+ISBNINVALIDCHECKSUM_RE = (
+r'The ISBN checksum of ([A-Z0-9]*) is incorrect'
+)
+
+ISBNINVALIDLENGTH_RE = (
+r'The ISBN ([A-Z0-9]*) is not (10|13) digits long'
+)
+
+ISBNINVALIDCHARACTERS_RE = (
+r'The ISBN ([A-Z0-9]*) contains invalid characters'
+)
+
 
 class TestCosmeticChangesISBN(DefaultDrySiteTestCase):
 
 """Test CosmeticChanges ISBN fix."""
+
+INVALIDNUMBERLENGTH_RE = (
+r'The number has an invalid length'
+)
+INVALIDNUMBERCHECKSUM_RE = (
+r'The number\'s checksum or check digit is invalid'
+)
 
 def test_valid_isbn(self):
 """Test ISBN."""
@@ -54,17 +73,25 @@
 cc = CosmeticChangesToolkit(self.site, namespace=0)
 
 # Invalid characters
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229LOL')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (ISBNINVALIDLENGTH_RE + '|' +
+self.INVALIDNUMBERLENGTH_RE),
+   cc.fix_ISBN, 'ISBN 0975229LOL')
 # Invalid checksum
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (ISBNINVALIDCHECKSUM_RE + '|' +
+self.INVALIDNUMBERCHECKSUM_RE),
+   cc.fix_ISBN, 'ISBN 0975229801')
 # Invalid length
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752298')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (ISBNINVALIDLENGTH_RE + '|' +
+self.INVALIDNUMBERLENGTH_RE),
+   cc.fix_ISBN, 'ISBN 09752298')
 # X in the middle
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752X9801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (ISBNINVALIDCHARACTERS_RE + '|' +
+self.INVALIDNUMBERLENGTH_RE),
+   cc.fix_ISBN, 'ISBN 09752X9801')
 
 def test_ignore_invalid_isbn(self):
 """Test fixing ISBN numbers with an invalid ISBN."""
@@ -77,6 +104,10 @@
 class TestIsbn(TestCase):
 
 """Test ISBN-related classes and helper functions."""
+
+ISBNXINTHEMIDDLE_RE = (
+r'ISBN ([A-Z0-9]*): X is only allowed at the end of the ISBN'
+)
 
 net = False
 
@@ -94,10 +125,14 @@
 self.assertEqual(isbn13.code, '978-0-9752298-0-4')
 
 # Errors
-self.assertRaises(IsbnExc, ISBN10, '0975229LOL')  # Invalid characters
-self.assertRaises(IsbnExc, ISBN10, '0975229801')  # Invalid checksum
-self.assertRaises(IsbnExc, ISBN10, '09752298')  # Invalid length
-self.assertRaises(IsbnExc, ISBN10, '09752X9801')  # X in the middle
+self.assertRaisesRegex(IsbnExc, ISBNINVALIDCHARACTERS_RE,
+   ISBN10, '0975229LOL')  # Invalid characters
+self.assertRaisesRegex(IsbnExc, ISBNINVALIDCHECKSUM_RE,
+   ISBN10, '0975229801')  # Invalid checksum
+self.assertRaisesRegex(IsbnExc, ISBNINVALIDLENGTH_RE,
+   ISBN10, '09752298')  # Invalid length
+self.assertRaisesRegex(IsbnExc, self.ISBNXINTHEMIDDLE_RE,
+   ISBN10, '09752X9801')  # X in the middle
 
 def test_isbn13(self):
 """Test ISBN13."""
@@ -111,9 +146,12 @@
 self.assertEqual(isbn.code, '9788090273412')
 
 # Errors
-self.assertRaises(IsbnExc, ISBN13, '9783161484LOL')  # Invalid chars
-self.assertRaises(IsbnExc, ISBN13, '9783161484105')  # Invalid checksum
-self.assertRaises(IsbnExc, ISBN13, '9783161484')  # Invalid length
+self.assertRaisesRegex(IsbnExc, ISBNINVALIDCHARACTERS_RE,
+   ISBN13, 

[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Replace assertRaises with assertRaisesRegex in isbn_tests.py

2018-01-13 Thread Divadsn (Code Review)
Divadsn has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404085 )

Change subject: Replace assertRaises with assertRaisesRegex in isbn_tests.py
..

Replace assertRaises with assertRaisesRegex in isbn_tests.py

assertRaises is not as good of a test as asserRaisesRegex.
The latter has an extra parameter to match the exception message,
allowing more more precision when checking an error.

Bug: T154281
Change-Id: Iaab3472bbae926caf5d68239b3828b5691ee38b9
---
M tests/isbn_tests.py
1 file changed, 54 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/85/404085/1

diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index df00417..216a1f8 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -39,6 +39,19 @@
 
 """Test CosmeticChanges ISBN fix."""
 
+ISBNINVALIDCHECKSUM_RE = (
+r"ISBN-13: The ISBN ([A-Z0-9]*) is not 13 digits long\. / "
+r"ISBN-10: The ISBN checksum of ([A-Z0-9]*) is incorrect\."
+)
+ISBNINVALIDLENGTH_RE = (
+r"ISBN-13: The ISBN ([A-Z0-9]*) is not 13 digits long\. / "
+r"ISBN-10: The ISBN ([A-Z0-9]*) is not 10 digits long\."
+)
+ISBNXINTHEMIDDLE_RE = (
+r"ISBN-13: The ISBN ([A-Z0-9]*) contains invalid characters\. / "
+r"ISBN-10: The ISBN ([A-Z0-9]*) is not 10 digits long\."
+)
+
 def test_valid_isbn(self):
 """Test ISBN."""
 cc = CosmeticChangesToolkit(self.site, namespace=0)
@@ -54,17 +67,17 @@
 cc = CosmeticChangesToolkit(self.site, namespace=0)
 
 # Invalid characters
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229LOL')
+self.assertRaisesRegex(AnyIsbnValidationException, 
self.ISBNINVALIDLENGTH_RE,
+   cc.fix_ISBN, 'ISBN 0975229LOL')
 # Invalid checksum
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229801')
+self.assertRaisesRegex(AnyIsbnValidationException, 
self.ISBNINVALIDCHECKSUM_RE,
+   cc.fix_ISBN, 'ISBN 0975229801')
 # Invalid length
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752298')
+self.assertRaisesRegex(AnyIsbnValidationException, 
self.ISBNINVALIDLENGTH_RE,
+   cc.fix_ISBN, 'ISBN 09752298')
 # X in the middle
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752X9801')
+self.assertRaisesRegex(AnyIsbnValidationException, 
self.ISBNXINTHEMIDDLE_RE,
+   cc.fix_ISBN, 'ISBN 09752X9801')
 
 def test_ignore_invalid_isbn(self):
 """Test fixing ISBN numbers with an invalid ISBN."""
@@ -77,6 +90,23 @@
 class TestIsbn(TestCase):
 
 """Test ISBN-related classes and helper functions."""
+
+ISBNINVALIDCHARACTERS_RE = (
+r"The ISBN ([A-Z0-9]*) contains invalid characters"
+)
+ISBNINVALIDCHECKSUM_RE = (
+r"The ISBN checksum of ([A-Z0-9]*) is incorrect"
+)
+ISBNINVALIDLENGTH_RE = (
+r"The ISBN ([A-Z0-9]*) is not (10|13) digits long"
+)
+ISBNBOTHINVALIDLENGTH_RE = (
+r"ISBN-13: The ISBN ([A-Z0-9]*) is not 13 digits long\. / "
+r"ISBN-10: The ISBN ([A-Z0-9]*) is not 10 digits long\."
+)
+ISBNXINTHEMIDDLE_RE = (
+r"ISBN ([A-Z0-9]*): X is only allowed at the end of the ISBN"
+)
 
 net = False
 
@@ -94,10 +124,14 @@
 self.assertEqual(isbn13.code, '978-0-9752298-0-4')
 
 # Errors
-self.assertRaises(IsbnExc, ISBN10, '0975229LOL')  # Invalid characters
-self.assertRaises(IsbnExc, ISBN10, '0975229801')  # Invalid checksum
-self.assertRaises(IsbnExc, ISBN10, '09752298')  # Invalid length
-self.assertRaises(IsbnExc, ISBN10, '09752X9801')  # X in the middle
+self.assertRaisesRegex(IsbnExc, self.ISBNINVALIDCHARACTERS_RE,
+   ISBN10, '0975229LOL')  # Invalid characters
+self.assertRaisesRegex(IsbnExc, self.ISBNINVALIDCHECKSUM_RE,
+   ISBN10, '0975229801')  # Invalid checksum
+self.assertRaisesRegex(IsbnExc, self.ISBNINVALIDLENGTH_RE,
+   ISBN10, '09752298')  # Invalid length
+self.assertRaisesRegex(IsbnExc, self.ISBNXINTHEMIDDLE_RE,
+   ISBN10, '09752X9801')  # X in the middle
 
 def test_isbn13(self):
 """Test ISBN13."""
@@ -111,19 +145,20 @@
 self.assertEqual(isbn.code, '9788090273412')
 
 # Errors
-self.assertRaises(IsbnExc, ISBN13, '9783161484LOL')  # Invalid chars
-self.assertRaises(IsbnExc, ISBN13, '9783161484105')  # Invalid checksum
-self.assertRaises(IsbnExc, ISBN13, '9783161484')  # Invalid length
+ 

[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Replace assertRaises with assertRaisesRegex in isbn_tests.py

2017-12-19 Thread Xqt (Code Review)
Xqt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399348 )

Change subject: Replace assertRaises with assertRaisesRegex in isbn_tests.py
..

Replace assertRaises with assertRaisesRegex in isbn_tests.py

assertRaises is not as good of a test as assertRaisesRegex.
The latter has an extra parameter to match the exception message,
allowing more precision when checking an error.

Change restored after revert in Ib41b30

Bug: T154281
Change-Id: Id67d5b76c0dc5a70289478d842cd3ebdc28b1b85
---
M tests/isbn_tests.py
1 file changed, 21 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/48/399348/1

diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index df00417..fc48a08 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -39,6 +39,11 @@
 
 """Test CosmeticChanges ISBN fix."""
 
+ISBN_DIGITERROR_RE = 'ISBN [0-9]+ is not [0-9]+ digits long'
+ISBN_INVALIDERROR_RE = 'Invalid ISBN found'
+ISBN_CHECKSUMERROR_RE = 'ISBN checksum of [0-9]+ is incorrect'
+ISBN_INVALIDCHARERROR_RE = 'ISBN [0-9a-zA-Z]+ contains invalid characters'
+
 def test_valid_isbn(self):
 """Test ISBN."""
 cc = CosmeticChangesToolkit(self.site, namespace=0)
@@ -54,17 +59,25 @@
 cc = CosmeticChangesToolkit(self.site, namespace=0)
 
 # Invalid characters
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229LOL')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_DIGITERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 0975229LOL')
 # Invalid checksum
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_CHECKSUMERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 0975229801')
 # Invalid length
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752298')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_DIGITERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 09752298')
 # X in the middle
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752X9801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_INVALIDCHARERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 09752X9801')
 
 def test_ignore_invalid_isbn(self):
 """Test fixing ISBN numbers with an invalid ISBN."""

-- 
To view, visit https://gerrit.wikimedia.org/r/399348
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id67d5b76c0dc5a70289478d842cd3ebdc28b1b85
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt 
Gerrit-Reviewer: Ryan10145 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Replace assertRaises with assertRaisesRegex in isbn_tests.py

2017-12-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399134 )

Change subject: Replace assertRaises with assertRaisesRegex in isbn_tests.py
..


Replace assertRaises with assertRaisesRegex in isbn_tests.py

assertRaises is not as good of a test as assertRaisesRegex.
The latter has an extra parameter to match the exception message,
allowing more precision when checking an error.

Bug: T154281
Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e
---
M tests/isbn_tests.py
1 file changed, 21 insertions(+), 8 deletions(-)

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



diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index df00417..fc48a08 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -39,6 +39,11 @@
 
 """Test CosmeticChanges ISBN fix."""
 
+ISBN_DIGITERROR_RE = 'ISBN [0-9]+ is not [0-9]+ digits long'
+ISBN_INVALIDERROR_RE = 'Invalid ISBN found'
+ISBN_CHECKSUMERROR_RE = 'ISBN checksum of [0-9]+ is incorrect'
+ISBN_INVALIDCHARERROR_RE = 'ISBN [0-9a-zA-Z]+ contains invalid characters'
+
 def test_valid_isbn(self):
 """Test ISBN."""
 cc = CosmeticChangesToolkit(self.site, namespace=0)
@@ -54,17 +59,25 @@
 cc = CosmeticChangesToolkit(self.site, namespace=0)
 
 # Invalid characters
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229LOL')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_DIGITERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 0975229LOL')
 # Invalid checksum
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_CHECKSUMERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 0975229801')
 # Invalid length
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752298')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_DIGITERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 09752298')
 # X in the middle
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752X9801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   (self.ISBN_INVALIDCHARERROR_RE + '|' +
+self.ISBN_INVALIDERROR_RE),
+   cc.fix_ISBN, 'ISBN 09752X9801')
 
 def test_ignore_invalid_isbn(self):
 """Test fixing ISBN numbers with an invalid ISBN."""

-- 
To view, visit https://gerrit.wikimedia.org/r/399134
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ryan10145 
Gerrit-Reviewer: Dalba 
Gerrit-Reviewer: Framawiki 
Gerrit-Reviewer: John Vandenberg 
Gerrit-Reviewer: Ryan10145 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Replace assertRaises with assertRaisesRegex in isbn_tests.py

2017-12-18 Thread Ryan10145 (Code Review)
Ryan10145 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399134 )

Change subject: Replace assertRaises with assertRaisesRegex in isbn_tests.py
..

Replace assertRaises with assertRaisesRegex in isbn_tests.py

assertRaises is not as good of a test as asserRaisesRegex. The latter has an 
extra parameter to match the exception message, allowing more more precision 
when checking an error.

Bug: T154281
Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e
---
M tests/isbn_tests.py
1 file changed, 10 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/34/399134/1

diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index df00417..bc31b0e 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -39,6 +39,8 @@
 
 """Test CosmeticChanges ISBN fix."""
 
+ISBN_DIGITERROR_RE = 'The ISBN [0-9]+ is not [0-9]+ digits long.'
+
 def test_valid_isbn(self):
 """Test ISBN."""
 cc = CosmeticChangesToolkit(self.site, namespace=0)
@@ -54,17 +56,17 @@
 cc = CosmeticChangesToolkit(self.site, namespace=0)
 
 # Invalid characters
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229LOL')
+self.assertRaisesRegex(AnyIsbnValidationException, 
+   self.ISBN_DIGITERROR_RE, cc.fix_ISBN, 'ISBN 0975229LOL')
 # Invalid checksum
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 0975229801')
+self.assertRaisesRegex(AnyIsbnValidationException, 
+   'The ISBN checksum of [0-9]+ is incorrect.', cc.fix_ISBN, 'ISBN 
0975229801')
 # Invalid length
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752298')
+self.assertRaisesRegex(AnyIsbnValidationException, 
+   self.ISBN_DIGITERROR_RE, cc.fix_ISBN, 'ISBN 09752298')
 # X in the middle
-self.assertRaises(AnyIsbnValidationException,
-  cc.fix_ISBN, 'ISBN 09752X9801')
+self.assertRaisesRegex(AnyIsbnValidationException,
+   'The ISBN [0-9a-zA-Z]+ contains invalid characters.', 
cc.fix_ISBN, 'ISBN 09752X9801')
 
 def test_ignore_invalid_isbn(self):
 """Test fixing ISBN numbers with an invalid ISBN."""

-- 
To view, visit https://gerrit.wikimedia.org/r/399134
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ryan10145 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits