def test_invalid_isbn(self): """Test that it'll fail when the ISBN is invalid.""" cc = CosmeticChangesToolkit(self.site, namespace=0) # Invalid characters with self.assertRaisesRegex( AnyIsbnValidationException, '|'.join( (self.ISBN_DIGITERROR_RE, self.ISBN_INVALIDERROR_RE, self.ISBN_INVALIDLENGTHERROR_RE))): cc.fix_ISBN('ISBN 0975229LOL') # Invalid checksum with self.assertRaisesRegex( AnyIsbnValidationException, '|'.join( (self.ISBN_CHECKSUMERROR_RE, self.ISBN_INVALIDERROR_RE, self.ISBN_INVALIDLENGTHERROR_RE, self.ISBN_INVALIDCHECKERROR_RE))): cc.fix_ISBN('ISBN 0975229801') # Invalid length with self.assertRaisesRegex( AnyIsbnValidationException, '|'.join( (self.ISBN_DIGITERROR_RE, self.ISBN_INVALIDERROR_RE, self.ISBN_INVALIDLENGTHERROR_RE))): cc.fix_ISBN('ISBN 09752298') # X in the middle with self.assertRaisesRegex( AnyIsbnValidationException, '|'.join( (self.ISBN_INVALIDCHARERROR_RE, self.ISBN_INVALIDERROR_RE, self.ISBN_INVALIDLENGTHERROR_RE))): cc.fix_ISBN('ISBN 09752X9801')
def test_ignore_invalid_isbn(self): cc = CosmeticChangesToolkit(self.site, namespace=0, ignore=CANCEL_MATCH) text = cc.fix_ISBN(' ISBN 0975229LOL ISBN 9780975229804 ') self.assertEqual(text, ' ISBN 0975229LOL ISBN 978-0-9752298-0-4 ')
def test_valid_isbn(self): """Test ISBN.""" cc = CosmeticChangesToolkit(self.site, namespace=0) text = cc.fix_ISBN(' ISBN 097522980x ') self.assertEqual(text, ' ISBN 0-9752298-0-X ') text = cc.fix_ISBN(' ISBN 9780975229804 ') self.assertEqual(text, ' ISBN 978-0-9752298-0-4 ')
def treat_page(self) -> None: """Treat page with the cosmetic toolkit.""" cc_toolkit = CosmeticChangesToolkit(self.current_page, ignore=self.opt.ignore) changed_text = cc_toolkit.change(self.current_page.get()) if changed_text is not False: self.put_current(new_text=changed_text, summary=self.opt.summary, asynchronous=self.opt['async'])
def test_valid_isbn_failing(self): """Test ISBN. This test fails with current library parts. """ cc = CosmeticChangesToolkit(self.site, namespace=0) text = cc.fix_ISBN(' ISBN 9783955390631 ') self.assertEqual(text, ' ISBN 978-3-95539-063-1 ') text = cc.fix_ISBN(' ISBN 9791091447034 ') self.assertEqual(text, ' ISBN 979-10-91447-03-4 ')
def treat_page(self) -> None: """Treat page with the cosmetic toolkit. .. versionchanged:: 7.0 skip if InvalidPageError is raised """ cc_toolkit = CosmeticChangesToolkit(self.current_page, ignore=self.opt.ignore) try: old_text = self.current_page.text except InvalidPageError: pywikibot.exception() return new_text = cc_toolkit.change(old_text) if new_text is not False: self.put_current(new_text=new_text, summary=self.opt.summary, asynchronous=self.opt['async'])
def test_invalid_isbn(self): cc = CosmeticChangesToolkit(self.site, namespace=0) self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 0975229LOL') # Invalid characters self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 0975229801') # Invalid checksum self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 09752298') # Invalid length self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 09752X9801') # X in the middle
def test_invalid_isbn(self): """Test that it'll fail when the ISBN is invalid.""" cc = CosmeticChangesToolkit(self.site, namespace=0) # Invalid characters self.assertRaises(AnyIsbnValidationException, cc.fix_ISBN, 'ISBN 0975229LOL') # Invalid checksum self.assertRaises(AnyIsbnValidationException, cc.fix_ISBN, 'ISBN 0975229801') # Invalid length self.assertRaises(AnyIsbnValidationException, cc.fix_ISBN, 'ISBN 09752298') # X in the middle self.assertRaises(AnyIsbnValidationException, cc.fix_ISBN, 'ISBN 09752X9801')
def test_valid_isbn(self): """Test ISBN.""" cc = CosmeticChangesToolkit(self.site, namespace=0) text = cc.fix_ISBN(' ISBN 097522980x ') self.assertEqual(text, ' ISBN 0-9752298-0-X ') text = cc.fix_ISBN(' ISBN 9780975229804 ') self.assertEqual(text, ' ISBN 978-0-9752298-0-4 ') text = cc.fix_ISBN(' ISBN 9783955390631 ') self.assertEqual(text, ' ISBN 978-3-95539-063-1 ') text = cc.fix_ISBN(' ISBN 9791091447034 ') self.assertEqual(text, ' ISBN 979-10-91447-03-4 ')
def test_invalid_isbn(self): """Test that it'll fail when the ISBN is invalid.""" cc = CosmeticChangesToolkit(self.site, namespace=0) # Invalid characters self.assertRaisesRegex(AnyIsbnValidationException, (ISBNINVALIDLENGTH_RE + '|' + self.INVALIDNUMBERLENGTH_RE), cc.fix_ISBN, 'ISBN 0975229LOL') # Invalid checksum self.assertRaisesRegex(AnyIsbnValidationException, (ISBNINVALIDCHECKSUM_RE + '|' + self.INVALIDNUMBERCHECKSUM_RE), cc.fix_ISBN, 'ISBN 0975229801') # Invalid length self.assertRaisesRegex(AnyIsbnValidationException, (ISBNINVALIDLENGTH_RE + '|' + self.INVALIDNUMBERLENGTH_RE), cc.fix_ISBN, 'ISBN 09752298') # X in the middle self.assertRaisesRegex(AnyIsbnValidationException, (ISBNINVALIDCHARACTERS_RE + '|' + self.INVALIDNUMBERLENGTH_RE), cc.fix_ISBN, 'ISBN 09752X9801')
def setUpClass(cls): """Setup class for all tests.""" super(TestCosmeticChanges, cls).setUpClass() cls.cct = CosmeticChangesToolkit(cls.site, namespace=0, pageTitle='Test')
def setUpClass(cls): """Setup class for all tests.""" super(TestCosmeticChanges, cls).setUpClass() cls.cct = CosmeticChangesToolkit(Page(cls.site, 'Test'))
def test_ignore_invalid_isbn(self): """Test fixing ISBN numbers with an invalid ISBN.""" cc = CosmeticChangesToolkit(self.site, namespace=0, ignore=CANCEL_MATCH) text = cc.fix_ISBN(' ISBN 0975229LOL ISBN 9780975229804 ') self.assertEqual(text, ' ISBN 0975229LOL ISBN 978-0-9752298-0-4 ')