Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions test/models/test_repr.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import inspect
from typing import Any

from unittest import TestCase
import _models # type: ignore # did not set types for this
import tableauserverclient as TSC

from typing import Any
import pytest


# ensure that all models that don't need parameters can be instantiated
Expand All @@ -31,21 +31,16 @@ def instantiate_class(name: str, obj: Any):
print(f"Class '{name}' does not have a constructor (__init__ method).")


class TestAllModels(TestCase):
# not all models have __repr__ yet: see above list
def test_repr_is_implemented(self):
m = _models.get_defined_models()
for model in m:
with self.subTest(model.__name__, model=model):
print(model.__name__, type(model.__repr__).__name__)
self.assertEqual(type(model.__repr__).__name__, "function")
def is_concrete(obj: Any):
return inspect.isclass(obj) and not inspect.isabstract(obj)

# 2 - Iterate through the objects in the module
def test_by_reflection(self):
for class_name, obj in inspect.getmembers(TSC, is_concrete):
with self.subTest(class_name, obj=obj):
instantiate_class(class_name, obj)

@pytest.mark.parametrize("class_name, obj", inspect.getmembers(TSC, is_concrete))
def test_by_reflection(class_name, obj):
instantiate_class(class_name, obj)

def is_concrete(obj: Any):
return inspect.isclass(obj) and not inspect.isabstract(obj)

@pytest.mark.parametrize("model", _models.get_defined_models())
def test_repr_is_implemented(model):
print(model.__name__, type(model.__repr__).__name__)
assert type(model.__repr__).__name__ == "function"
Loading