Skip to content

Commit

Permalink
Added test cases for smoke.read
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaruland committed Feb 6, 2024
1 parent 4e42da1 commit 1aa3b61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
40 changes: 29 additions & 11 deletions tiled/_tests/test_client_smoke.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import collections

import numpy as np
import pytest

from ..adapters.array import ArrayAdapter
Expand All @@ -9,20 +8,39 @@
from ..server.app import build_app


def f():
raise Exception("test!")
class Broken(Exception):
pass


class BrokenArrayAdapter(ArrayAdapter):
def read(self, *args, **kwargs):
raise Broken

def read_block(self, *args, **kwargs):
raise Broken


def test_smoke_read():
data = collections.defaultdict(f)
data["A"] = ArrayAdapter.from_array([1, 2, 3], metadata={"A": "a"})
@pytest.fixture(scope="module")
def context():
mapping = {
"A": ArrayAdapter.from_array(np.array([1, 2, 3]), metadata={"A": "a"}),
"B": BrokenArrayAdapter.from_array(np.array([4, 5, 6]), metadata={"B": "b"}),
}

tree = MapAdapter(data)
tree = MapAdapter(mapping)
with Context.from_app(build_app(tree)) as context:
client = from_context(context)
yield context


def test_smoke_read_list(context):
client = from_context(context)

faulty_list = read(client)
assert len(faulty_list) == 1

with pytest.raises(Exception):
data["B"]

def test_smoke_read_raise(context):
client = from_context(context)

with pytest.raises(Broken):
read(client, strict=True)
8 changes: 4 additions & 4 deletions tiled/client/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ def read(node, verbose=False, strict=False):
faulty_entries = []
if node.structure_family == StructureFamily.container:
for key, child_node in node.items():
fault_result = read(child_node, verbose=verbose)
fault_result = read(child_node, verbose=verbose, strict=strict)
faulty_entries.extend(fault_result)
else:
try:
tmp = node.read() # noqa: F841
except Exception as err:
if strict:
raise
faulty_entries.append(node.uri)
if verbose:
print(f"ERROR: {node.item['id']} - {err!r}", file=sys.stderr)
faulty_entries.append(node.uri)
if strict:
raise
else:
if verbose:
print(f"SUCCESS: {node.item['id']} ", file=sys.stderr)
Expand Down

0 comments on commit 1aa3b61

Please sign in to comment.