Use six to avoid obsolete unittest assertions #2254
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves import queue
|
from six.moves import queue
|
||||||
|
|
||||||
from .partial import TestPartialRun
|
from .partial import TestPartialRun
|
||||||
|
@ -91,8 +92,8 @@ class TestAddressGenerator(TestPartialRun):
|
||||||
self.command_queue.put((
|
self.command_queue.put((
|
||||||
'createRandomAddress', 4, 1, 'test_random', 1, '', False, 0, 0))
|
'createRandomAddress', 4, 1, 'test_random', 1, '', False, 0, 0))
|
||||||
addr = self.return_queue.get()
|
addr = self.return_queue.get()
|
||||||
self.assertRegexpMatches(addr, r'^BM-')
|
six.assertRegex(self, addr, r'^BM-')
|
||||||
self.assertRegexpMatches(addr[3:], r'[a-zA-Z1-9]+$')
|
six.assertRegex(self, addr[3:], r'[a-zA-Z1-9]+$')
|
||||||
self.assertLessEqual(len(addr[3:]), 40)
|
self.assertLessEqual(len(addr[3:]), 40)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
|
@ -5,11 +5,11 @@ Tests using API.
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from six.moves import xmlrpc_client # nosec
|
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
import six
|
||||||
|
from six.moves import xmlrpc_client # nosec
|
||||||
|
|
||||||
from .samples import (
|
from .samples import (
|
||||||
sample_deterministic_addr3, sample_deterministic_addr4, sample_seed,
|
sample_deterministic_addr3, sample_deterministic_addr4, sample_seed,
|
||||||
|
@ -174,29 +174,29 @@ class TestAPI(TestAPIProto):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.api.getDeterministicAddress(self._seed, 3, 1),
|
self.api.getDeterministicAddress(self._seed, 3, 1),
|
||||||
sample_deterministic_addr3)
|
sample_deterministic_addr3)
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.getDeterministicAddress(self._seed, 2, 1),
|
self, self.api.getDeterministicAddress(self._seed, 2, 1),
|
||||||
r'^API Error 0002:')
|
r'^API Error 0002:')
|
||||||
|
|
||||||
# This is here until the streams will be implemented
|
# This is here until the streams will be implemented
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.getDeterministicAddress(self._seed, 3, 2),
|
self, self.api.getDeterministicAddress(self._seed, 3, 2),
|
||||||
r'API Error 0003:')
|
r'API Error 0003:')
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed, 1, 4, 2),
|
self, self.api.createDeterministicAddresses(self._seed, 1, 4, 2),
|
||||||
r'API Error 0003:')
|
r'API Error 0003:')
|
||||||
|
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses('', 1),
|
self, self.api.createDeterministicAddresses('', 1),
|
||||||
r'API Error 0001:')
|
r'API Error 0001:')
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed, 1, 2),
|
self, self.api.createDeterministicAddresses(self._seed, 1, 2),
|
||||||
r'API Error 0002:')
|
r'API Error 0002:')
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed, 0),
|
self, self.api.createDeterministicAddresses(self._seed, 0),
|
||||||
r'API Error 0004:')
|
r'API Error 0004:')
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed, 1000),
|
self, self.api.createDeterministicAddresses(self._seed, 1000),
|
||||||
r'API Error 0005:')
|
r'API Error 0005:')
|
||||||
|
|
||||||
addresses = json.loads(
|
addresses = json.loads(
|
||||||
|
@ -210,8 +210,8 @@ class TestAPI(TestAPIProto):
|
||||||
def test_create_random_address(self):
|
def test_create_random_address(self):
|
||||||
"""API command 'createRandomAddress': basic BM-address validation"""
|
"""API command 'createRandomAddress': basic BM-address validation"""
|
||||||
addr = self._add_random_address('random_1')
|
addr = self._add_random_address('random_1')
|
||||||
self.assertRegexpMatches(addr, r'^BM-')
|
six.assertRegex(self, addr, r'^BM-')
|
||||||
self.assertRegexpMatches(addr[3:], r'[a-zA-Z1-9]+$')
|
six.assertRegex(self, addr[3:], r'[a-zA-Z1-9]+$')
|
||||||
# Whitepaper says "around 36 character"
|
# Whitepaper says "around 36 character"
|
||||||
self.assertLessEqual(len(addr[3:]), 40)
|
self.assertLessEqual(len(addr[3:]), 40)
|
||||||
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
||||||
|
@ -411,7 +411,7 @@ class TestAPI(TestAPIProto):
|
||||||
self.assertEqual(self.api.enableAddress(addr, False), 'success')
|
self.assertEqual(self.api.enableAddress(addr, False), 'success')
|
||||||
result = self.api.sendBroadcast(
|
result = self.api.sendBroadcast(
|
||||||
addr, base64.encodestring('test_subject'), msg)
|
addr, base64.encodestring('test_subject'), msg)
|
||||||
self.assertRegexpMatches(result, r'^API Error 0014:')
|
six.assertRegex(self, result, r'^API Error 0014:')
|
||||||
finally:
|
finally:
|
||||||
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ class TestAPI(TestAPIProto):
|
||||||
result = self.api.sendBroadcast(
|
result = self.api.sendBroadcast(
|
||||||
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',
|
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',
|
||||||
base64.encodestring('test_subject'), msg)
|
base64.encodestring('test_subject'), msg)
|
||||||
self.assertRegexpMatches(result, r'^API Error 0013:')
|
six.assertRegex(self, result, r'^API Error 0013:')
|
||||||
|
|
||||||
def test_chan(self):
|
def test_chan(self):
|
||||||
"""Testing chan creation/joining"""
|
"""Testing chan creation/joining"""
|
||||||
|
@ -435,7 +435,7 @@ class TestAPI(TestAPIProto):
|
||||||
self.assertEqual(self.api.joinChan(self._seed, addr), 'success')
|
self.assertEqual(self.api.joinChan(self._seed, addr), 'success')
|
||||||
self.assertEqual(self.api.leaveChan(addr), 'success')
|
self.assertEqual(self.api.leaveChan(addr), 'success')
|
||||||
# Joining with wrong address should fail
|
# Joining with wrong address should fail
|
||||||
self.assertRegexpMatches(
|
six.assertRegex(
|
||||||
self.api.joinChan(self._seed, 'BM-2cWzSnwjJ7yRP3nLEW'),
|
self, self.api.joinChan(self._seed, 'BM-2cWzSnwjJ7yRP3nLEW'),
|
||||||
r'^API Error 0008:'
|
r'^API Error 0008:'
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,6 +7,8 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from pybitmessage import highlevelcrypto
|
from pybitmessage import highlevelcrypto
|
||||||
from pybitmessage.storage import storage
|
from pybitmessage.storage import storage
|
||||||
|
|
||||||
|
@ -50,8 +52,8 @@ class TestStorageAbstract(unittest.TestCase):
|
||||||
|
|
||||||
def test_inventory_storage(self):
|
def test_inventory_storage(self):
|
||||||
"""Check inherited abstract methods"""
|
"""Check inherited abstract methods"""
|
||||||
with self.assertRaisesRegexp(
|
with six.assertRaisesRegex(
|
||||||
TypeError, "^Can't instantiate abstract class.*"
|
self, TypeError, "^Can't instantiate abstract class.*"
|
||||||
"methods __contains__, __delitem__, __getitem__, __iter__,"
|
"methods __contains__, __delitem__, __getitem__, __iter__,"
|
||||||
" __len__, __setitem__"
|
" __len__, __setitem__"
|
||||||
): # pylint: disable=abstract-class-instantiated
|
): # pylint: disable=abstract-class-instantiated
|
||||||
|
|
|
@ -5,6 +5,8 @@ Testing the logger configuration
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from .test_process import TestProcessProto
|
from .test_process import TestProcessProto
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,5 +54,5 @@ handlers=default
|
||||||
|
|
||||||
self._stop_process()
|
self._stop_process()
|
||||||
data = open(self.log_file).read()
|
data = open(self.log_file).read()
|
||||||
self.assertRegexpMatches(data, self.pattern)
|
six.assertRegex(self, data, self.pattern)
|
||||||
self.assertRegexpMatches(data, 'Loaded logger configuration')
|
six.assertRegex(self, data, 'Loaded logger configuration')
|
||||||
|
|
Reference in New Issue
Block a user