Skip to content

Commit

Permalink
Cleans up some pytest things:
Browse files Browse the repository at this point in the history
* organized PoissonMux tests into classes, S.T. the `mux_class` can, where possible, be passed down from the class, instead of called at each test.
* This lead to a particular python problem where `T.__eq_batch` wasn't working because it was looking for __eq_batch in the Test Class instead of in pescador.util, which was yucky, so I was forced to change `__eq_batch` into `_eq_batch`. Made this change for `__eq_lists` so that it matches.
* Got a deprecation warning from pytest about how you're stupposed to use `pytest.param(marks=...`) instead of `pytest.mark.xfail()` on parameters going forward, so I fixed some of those.
  • Loading branch information
cjacoby committed Dec 13, 2017
1 parent c922d03 commit 94b4765
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 327 deletions.
7 changes: 4 additions & 3 deletions tests/test_buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __unpack_stream(stream):

estimate = list(__unpack_stream(estimate))

T.__eq_lists(reference, estimate)
T._eq_lists(reference, estimate)

estimate = pescador.BufferedStreamer(gen_stream, buf_size)

Expand All @@ -40,8 +40,9 @@ def __unpack_stream(stream):

@pytest.mark.parametrize('items',
[['X'], ['Y'], ['X', 'Y'], ['Y', 'X'],
pytest.mark.xfail([],
raises=pescador.PescadorError)])
pytest.param([],
marks=pytest.mark.xfail(
raises=pescador.PescadorError))])
@pytest.mark.parametrize('dimension', [1, 2, 3])
@pytest.mark.parametrize('batch_size', [1, 2, 5, 17])
@pytest.mark.parametrize('buf_size', [1, 2, 5, 17, 100])
Expand Down
12 changes: 6 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def test_streamer_generator_func():
actual1 = list(streamer)
assert len(expected) == len(actual1) == n_items
for b1, b2 in zip(expected, actual1):
T.__eq_batch(b1, b2)
T._eq_batch(b1, b2)

# Test __iter__ interface
actual2 = list(streamer)
assert len(expected) == len(actual2) == n_items
for b1, b2 in zip(expected, actual2):
T.__eq_batch(b1, b2)
T._eq_batch(b1, b2)


@pytest.mark.parametrize('items',
Expand All @@ -66,7 +66,7 @@ def test_streamer_tuple(items):
assert len(reference) == len(query)
for b1, b2 in zip(reference, query):
assert isinstance(b2, tuple)
T.__eq_lists(b1, b2)
T._eq_lists(b1, b2)


@pytest.mark.parametrize('n_max', [None, 10, 50, 100])
Expand All @@ -89,7 +89,7 @@ def test_streamer_finite(n_max, stream_size, generate):

query = list(gen)
for b1, b2 in zip(reference, query):
T.__eq_batch(b1, b2)
T._eq_batch(b1, b2)


@pytest.mark.parametrize('n_max', [10, 50])
Expand All @@ -107,7 +107,7 @@ def test_streamer_infinite(n_max, stream_size):
query = list(streamer.iterate(max_iter=n_max))

for b1, b2 in zip(reference, query):
T.__eq_batch(b1, b2)
T._eq_batch(b1, b2)


@pytest.mark.parametrize('n_max', [10, 50])
Expand All @@ -128,7 +128,7 @@ def test_streamer_in_streamer(n_max, stream_size):
query = list(streamer2.iterate(max_iter=n_max))

for b1, b2 in zip(reference, query):
T.__eq_batch(b1, b2)
T._eq_batch(b1, b2)


@pytest.mark.parametrize('generate', [False, True])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test___stack_data():
data = [{"X": np.array([n])} for n in range(n_items)]
expected = {"X": np.arange(n_items).reshape(-1, 1)}
output = pescador.maps.__stack_data(data)
T.__eq_batch(expected, output)
T._eq_batch(expected, output)


def test_buffer_stream():
Expand All @@ -24,13 +24,13 @@ def test_buffer_stream():
outputs = list(stream)
assert len(outputs) == (len(expected) - 1)
for exp, obs in zip(expected, outputs):
T.__eq_batch(exp, obs)
T._eq_batch(exp, obs)

stream = pescador.maps.buffer_stream(inputs, buffer_size=4, partial=True)
outputs = list(stream)
assert len(outputs) == len(expected)
for exp, obs in zip(expected, outputs):
T.__eq_batch(exp, obs)
T._eq_batch(exp, obs)

with pytest.raises(pescador.maps.DataError):
for not_data in pescador.maps.buffer_stream([1, 2, 3, 4], 2):
Expand Down

0 comments on commit 94b4765

Please sign in to comment.