use six.assertRaisesRegex, six.assertRegex, six.assertNotRegex

This commit is contained in:
Kashiko Koibumi 2024-05-25 13:07:59 +09:00
parent 21a7bdba44
commit 81a6bdb223
No known key found for this signature in database
GPG Key ID: 8F06E069E37C40C4
4 changed files with 22 additions and 18 deletions

View File

@ -3,6 +3,7 @@
from binascii import unhexlify
from six.moves import queue
import six
from .partial import TestPartialRun
from .samples import (
@ -91,8 +92,8 @@ class TestAddressGenerator(TestPartialRun):
self.command_queue.put((
'createRandomAddress', 4, 1, 'test_random', 1, '', False, 0, 0))
addr = self.return_queue.get()
self.assertRegexpMatches(addr, r'^BM-')
self.assertRegexpMatches(addr[3:], r'[a-zA-Z1-9]+$')
six.assertRegex(self, addr, r'^BM-')
six.assertRegex(self, addr[3:], r'[a-zA-Z1-9]+$')
self.assertLessEqual(len(addr[3:]), 40)
self.assertEqual(

View File

@ -8,6 +8,7 @@ import time
from binascii import hexlify
from six.moves import xmlrpc_client # nosec
import six
import psutil
@ -174,28 +175,28 @@ class TestAPI(TestAPIProto):
self.assertEqual(
self.api.getDeterministicAddress(self._seed, 3, 1),
sample_deterministic_addr3)
self.assertRegexpMatches(
six.assertRegex(self,
self.api.getDeterministicAddress(self._seed, 2, 1),
r'^API Error 0002:')
# This is here until the streams will be implemented
self.assertRegexpMatches(
six.assertRegex(self,
self.api.getDeterministicAddress(self._seed, 3, 2),
r'API Error 0003:')
self.assertRegexpMatches(
six.assertRegex(self,
self.api.createDeterministicAddresses(self._seed, 1, 4, 2),
r'API Error 0003:')
self.assertRegexpMatches(
six.assertRegex(self,
self.api.createDeterministicAddresses('', 1),
r'API Error 0001:')
self.assertRegexpMatches(
six.assertRegex(self,
self.api.createDeterministicAddresses(self._seed, 1, 2),
r'API Error 0002:')
self.assertRegexpMatches(
six.assertRegex(self,
self.api.createDeterministicAddresses(self._seed, 0),
r'API Error 0004:')
self.assertRegexpMatches(
six.assertRegex(self,
self.api.createDeterministicAddresses(self._seed, 1000),
r'API Error 0005:')
@ -210,8 +211,8 @@ class TestAPI(TestAPIProto):
def test_create_random_address(self):
"""API command 'createRandomAddress': basic BM-address validation"""
addr = self._add_random_address('random_1')
self.assertRegexpMatches(addr, r'^BM-')
self.assertRegexpMatches(addr[3:], r'[a-zA-Z1-9]+$')
six.assertRegex(self, addr, r'^BM-')
six.assertRegex(self, addr[3:], r'[a-zA-Z1-9]+$')
# Whitepaper says "around 36 character"
self.assertLessEqual(len(addr[3:]), 40)
self.assertEqual(self.api.deleteAddress(addr), 'success')
@ -242,7 +243,7 @@ class TestAPI(TestAPIProto):
msg_subject = base64.encodestring('test_subject')
result = self.api.sendMessage(
sample_deterministic_addr4, addr, msg_subject, msg)
self.assertNotRegexpMatches(result, r'^API Error')
six.assertNotRegex(self, result, r'^API Error')
self.api.deleteAddress(addr)
# Remove known address
self.api.deleteAddressBookEntry(sample_deterministic_addr4)
@ -411,7 +412,7 @@ class TestAPI(TestAPIProto):
self.assertEqual(self.api.enableAddress(addr, False), 'success')
result = self.api.sendBroadcast(
addr, base64.encodestring('test_subject'), msg)
self.assertRegexpMatches(result, r'^API Error 0014:')
six.assertRegex(self, result, r'^API Error 0014:')
finally:
self.assertEqual(self.api.deleteAddress(addr), 'success')
@ -420,7 +421,7 @@ class TestAPI(TestAPIProto):
result = self.api.sendBroadcast(
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',
base64.encodestring('test_subject'), msg)
self.assertRegexpMatches(result, r'^API Error 0013:')
six.assertRegex(self, result, r'^API Error 0013:')
def test_chan(self):
"""Testing chan creation/joining"""
@ -435,7 +436,7 @@ class TestAPI(TestAPIProto):
self.assertEqual(self.api.joinChan(self._seed, addr), 'success')
self.assertEqual(self.api.leaveChan(addr), 'success')
# Joining with wrong address should fail
self.assertRegexpMatches(
six.assertRegex(self,
self.api.joinChan(self._seed, 'BM-2cWzSnwjJ7yRP3nLEW'),
r'^API Error 0008:'
)

View File

@ -6,6 +6,7 @@ import struct
import tempfile
import time
import unittest
import six
from pybitmessage import highlevelcrypto
from pybitmessage.storage import storage
@ -50,7 +51,7 @@ class TestStorageAbstract(unittest.TestCase):
def test_inventory_storage(self):
"""Check inherited abstract methods"""
with self.assertRaisesRegexp(
with six.assertRaisesRegex(self,
TypeError, "^Can't instantiate abstract class.*"
"methods __contains__, __delitem__, __getitem__, __iter__,"
" __len__, __setitem__"

View File

@ -4,6 +4,7 @@ Testing the logger configuration
import os
import tempfile
import six
from .test_process import TestProcessProto
@ -52,5 +53,5 @@ handlers=default
self._stop_process()
data = open(self.log_file).read()
self.assertRegexpMatches(data, self.pattern)
self.assertRegexpMatches(data, 'Loaded logger configuration')
six.assertRegex(self, data, self.pattern)
six.assertRegex(self, data, 'Loaded logger configuration')