Skip to content

Commit a588d18

Browse files
committed
add init files to find test_repr, fix it to pass
black
1 parent 80f06cf commit a588d18

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

tableauserverclient/models/column_item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55

66
class ColumnItem:
7-
def __init__(self, name, description=None):
7+
def __init__(self, name=None, description=None):
88
self._id = None
99
self.description = description
10-
self.name = name
10+
self._name = name
1111

1212
def __repr__(self):
13-
return f"<{self.__class__.__name__} {self._id} {self.name} {self.description}>"
13+
return f"<{self.__class__.__name__} {self._id} {self._name} {self.description}>"
1414

1515
@property
1616
def id(self):

test/http/__init__.py

Whitespace-only changes.

test/models/__init__.py

Whitespace-only changes.

test/models/test_repr.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import inspect
22

33
from unittest import TestCase
4-
import _models # type: ignore # did not set types for this
4+
import tableauserverclient.models as TSC_models # type: ignore # did not set types for this
55
import tableauserverclient as TSC
66

77
from typing import Any
88

99

10-
# ensure that all models that don't need parameters can be instantiated
11-
# todo....
10+
# ensure that all models can be instantiated
1211
def instantiate_class(name: str, obj: Any):
1312
# Get the constructor (init) of the class
1413
constructor = getattr(obj, "__init__", None)
@@ -31,14 +30,38 @@ def instantiate_class(name: str, obj: Any):
3130
print(f"Class '{name}' does not have a constructor (__init__ method).")
3231

3332

33+
not_yet_done = [
34+
"DQWItem",
35+
"UnpopulatedPropertyError",
36+
"FavoriteItem",
37+
"FileuploadItem",
38+
"FlowRunItem",
39+
"IntervalItem",
40+
"LinkedTaskItem",
41+
"LinkedTaskStepItem",
42+
"LinkedTaskFlowRunItem",
43+
"Permission",
44+
"SiteAuthConfiguration",
45+
"Resource",
46+
"TagItem",
47+
"ExtractItem",
48+
]
49+
50+
3451
class TestAllModels(TestCase):
35-
# not all models have __repr__ yet: see above list
52+
53+
# confirm that all models can be instantiated without params, and have __repr__ implemented
54+
# not all do have __repr__ yet: see above list 'not_yet_done'
3655
def test_repr_is_implemented(self):
37-
m = _models.get_defined_models()
38-
for model in m:
39-
with self.subTest(model.__name__, model=model):
40-
print(model.__name__, type(model.__repr__).__name__)
41-
self.assertEqual(type(model.__repr__).__name__, "function")
56+
m = TSC_models
57+
for type_name in m.__dict__:
58+
if type_name in not_yet_done:
59+
continue
60+
model = getattr(m, type_name)
61+
if inspect.isclass(model):
62+
with self.subTest(type_name):
63+
self.assertTrue(hasattr(model, "__repr__"))
64+
self.assertEqual(type(model.__repr__).__name__, "function")
4265

4366
# 2 - Iterate through the objects in the module
4467
def test_by_reflection(self):

0 commit comments

Comments
 (0)