Skip to content

Commit 9977809

Browse files
authored
Fix test (#264)
* Fix test * Using pytest.raises instead of assert_raises
1 parent 6c120d8 commit 9977809

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

tests/test_api.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import random
88
import threading
99

10+
import pytest
1011
import six
1112
from six.moves import range
1213

1314
from happybase import Connection, ConnectionPool, NoConnectionsAvailable
1415

1516
HAPPYBASE_HOST = os.environ.get('HAPPYBASE_HOST')
16-
HAPPYBASE_PORT = os.environ.get('HAPPYBASE_PORT')
17+
HAPPYBASE_PORT = int(os.environ['HAPPYBASE_PORT']) if 'HAPPYBASE_PORT' in os.environ else None
1718
HAPPYBASE_COMPAT = os.environ.get('HAPPYBASE_COMPAT', '0.98')
1819
HAPPYBASE_TRANSPORT = os.environ.get('HAPPYBASE_TRANSPORT', 'buffered')
1920
KEEP_TABLE = ('HAPPYBASE_NO_CLEANUP' in os.environ)
@@ -68,7 +69,7 @@ def teardown_module():
6869

6970

7071
def test_connection_compat():
71-
with assert_raises(ValueError):
72+
with pytest.raises(ValueError):
7273
Connection(compat='0.1.invalid.version')
7374

7475

@@ -101,10 +102,10 @@ def test_prefix():
101102
c = Connection(autoconnect=False)
102103
assert b'foo' == c._table_name('foo')
103104

104-
with assert_raises(TypeError):
105+
with pytest.raises(TypeError):
105106
Connection(autoconnect=False, table_prefix=123)
106107

107-
with assert_raises(TypeError):
108+
with pytest.raises(TypeError):
108109
Connection(autoconnect=False, table_prefix_separator=2.1)
109110

110111

@@ -127,11 +128,11 @@ def test_table_regions():
127128

128129

129130
def test_invalid_table_create():
130-
with assert_raises(ValueError):
131+
with pytest.raises(ValueError):
131132
connection.create_table('sometable', families={})
132-
with assert_raises(TypeError):
133+
with pytest.raises(TypeError):
133134
connection.create_table('sometable', families=0)
134-
with assert_raises(TypeError):
135+
with pytest.raises(TypeError):
135136
connection.create_table('sometable', families=[])
136137

137138

@@ -175,7 +176,7 @@ def test_atomic_counters():
175176

176177

177178
def test_batch():
178-
with assert_raises(TypeError):
179+
with pytest.raises(TypeError):
179180
table.batch(timestamp='invalid')
180181

181182
b = table.batch()
@@ -192,10 +193,10 @@ def test_batch():
192193
b.put(b'row1', {b'cf1:col5': b'value5'})
193194
b.send()
194195

195-
with assert_raises(ValueError):
196+
with pytest.raises(ValueError):
196197
b = table.batch(batch_size=0)
197198

198-
with assert_raises(TypeError):
199+
with pytest.raises(TypeError):
199200
b = table.batch(transaction=True, batch_size=10)
200201

201202

@@ -212,13 +213,13 @@ def test_batch_context_managers():
212213
b'cf1:c5': b'anothervalue'})
213214
b.delete(b'row', [b'cf1:c3'])
214215

215-
with assert_raises(ValueError):
216+
with pytest.raises(ValueError):
216217
with table.batch(transaction=True) as b:
217218
b.put(b'fooz', {b'cf1:bar': b'baz'})
218219
raise ValueError
219220
assert {} == table.row(b'fooz', [b'cf1:bar'])
220221

221-
with assert_raises(ValueError):
222+
with pytest.raises(ValueError):
222223
with table.batch(transaction=False) as b:
223224
b.put(b'fooz', {b'cf1:bar': b'baz'})
224225
raise ValueError
@@ -246,10 +247,10 @@ def test_row():
246247
put = table.put
247248
row_key = b'row-test'
248249

249-
with assert_raises(TypeError):
250+
with pytest.raises(TypeError):
250251
row(row_key, 123)
251252

252-
with assert_raises(TypeError):
253+
with pytest.raises(TypeError):
253254
row(row_key, timestamp='invalid')
254255

255256
put(row_key, {b'cf1:col1': b'v1old'}, timestamp=1234)
@@ -289,10 +290,10 @@ def test_rows():
289290
data_old = {b'cf1:col1': b'v1old', b'cf1:col2': b'v2old'}
290291
data_new = {b'cf1:col1': b'v1new', b'cf1:col2': b'v2new'}
291292

292-
with assert_raises(TypeError):
293+
with pytest.raises(TypeError):
293294
table.rows(row_keys, object())
294295

295-
with assert_raises(TypeError):
296+
with pytest.raises(TypeError):
296297
table.rows(row_keys, timestamp='invalid')
297298

298299
for row_key in row_keys:
@@ -321,13 +322,13 @@ def test_cells():
321322
table.put(row_key, {col: b'old'}, timestamp=1234)
322323
table.put(row_key, {col: b'new'})
323324

324-
with assert_raises(TypeError):
325+
with pytest.raises(TypeError):
325326
table.cells(row_key, col, versions='invalid')
326327

327-
with assert_raises(TypeError):
328+
with pytest.raises(TypeError):
328329
table.cells(row_key, col, versions=3, timestamp='invalid')
329330

330-
with assert_raises(ValueError):
331+
with pytest.raises(ValueError):
331332
table.cells(row_key, col, versions=0)
332333

333334
results = table.cells(row_key, col, versions=1)
@@ -346,14 +347,14 @@ def test_cells():
346347

347348

348349
def test_scan():
349-
with assert_raises(TypeError):
350+
with pytest.raises(TypeError):
350351
list(table.scan(row_prefix='foobar', row_start='xyz'))
351352

352353
if connection.compat == '0.90':
353-
with assert_raises(NotImplementedError):
354+
with pytest.raises(NotImplementedError):
354355
list(table.scan(filter='foo'))
355356

356-
with assert_raises(ValueError):
357+
with pytest.raises(ValueError):
357358
list(table.scan(limit=0))
358359

359360
with table.batch() as b:
@@ -411,7 +412,7 @@ def calc_len(scanner):
411412
next(scanner)
412413
next(scanner)
413414
scanner.close()
414-
with assert_raises(StopIteration):
415+
with pytest.raises(StopIteration):
415416
next(scanner)
416417

417418

@@ -436,7 +437,7 @@ def test_scan_sorting():
436437
def test_scan_reverse():
437438

438439
if connection.compat < '0.98':
439-
with assert_raises(NotImplementedError):
440+
with pytest.raises(NotImplementedError):
440441
list(table.scan(reverse=True))
441442
return
442443

@@ -496,10 +497,10 @@ def test_delete():
496497

497498

498499
def test_connection_pool_construction():
499-
with assert_raises(TypeError):
500+
with pytest.raises(TypeError):
500501
ConnectionPool(size='abc')
501502

502-
with assert_raises(ValueError):
503+
with pytest.raises(ValueError):
503504
ConnectionPool(size=0)
504505

505506

@@ -559,7 +560,7 @@ def test_pool_exhaustion():
559560
pool = ConnectionPool(size=1, **connection_kwargs)
560561

561562
def run():
562-
with assert_raises(NoConnectionsAvailable):
563+
with pytest.raises(NoConnectionsAvailable):
563564
with pool.connection(timeout=.1) as connection:
564565
connection.tables()
565566

0 commit comments

Comments
 (0)