Skip to content

Commit 3791e8a

Browse files
committed
fix test/syntax failures from merge
1 parent d24c77e commit 3791e8a

File tree

3 files changed

+46
-98
lines changed

3 files changed

+46
-98
lines changed

tableauserverclient/models/column_item.py

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

55

66
class ColumnItem:
7-
def __init__(self, name=None, description=None):
7+
def __init__(self, name, 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):
@@ -68,4 +68,4 @@ def _parse_element(column_xml, ns):
6868
description = column_xml.get("description", None)
6969
remote_type = column_xml.get("remoteType", None)
7070

71-
return id, name, description, remote_type
71+
return id, name, description, remote_type

test/models/_models.py

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,27 @@
1010
)
1111

1212

13-
def get_defined_models():
14-
# nothing clever here: list was manually copied from tsc/models/__init__.py
15-
return [
16-
BackgroundJobItem,
17-
ConnectionItem,
18-
DataAccelerationReportItem,
19-
DataAlertItem,
20-
DatasourceItem,
21-
FlowItem,
22-
GroupItem,
23-
JobItem,
24-
MetricItem,
25-
PermissionsRule,
26-
ProjectItem,
27-
RevisionItem,
28-
ScheduleItem,
29-
SubscriptionItem,
30-
Credentials,
31-
JWTAuth,
32-
TableauAuth,
33-
PersonalAccessTokenAuth,
34-
ServerInfoItem,
35-
SiteItem,
36-
TaskItem,
37-
UserItem,
38-
ViewItem,
39-
WebhookItem,
40-
WorkbookItem,
41-
PaginationItem,
42-
Permission.Mode,
43-
Permission.Capability,
44-
DailyInterval,
45-
WeeklyInterval,
46-
MonthlyInterval,
47-
HourlyInterval,
48-
TableItem,
49-
Target,
50-
]
51-
52-
5313
def get_unimplemented_models():
5414
return [
15+
# these items should have repr , please fix
16+
CollectionItem,
17+
DQWItem,
18+
ExtensionsServer,
19+
ExtensionsSiteSettings,
20+
FileuploadItem,
21+
FlowRunItem,
22+
LinkedTaskFlowRunItem,
23+
LinkedTaskItem,
24+
LinkedTaskStepItem,
25+
SafeExtension,
26+
# these should be implemented together for consistency
27+
CSVRequestOptions,
28+
ExcelRequestOptions,
29+
ImageRequestOptions,
30+
PDFRequestOptions,
31+
PPTXRequestOptions,
32+
RequestOptions,
33+
# these don't need it
5534
FavoriteItem, # no repr because there is no state
5635
Resource, # list of type names
5736
TableauItem, # should be an interface

test/models/test_repr.py

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import inspect
22
from typing import Any
3-
4-
from unittest import TestCase
5-
import tableauserverclient.models as TSC_models # type: ignore # did not set types for this
3+
from test.models._models import get_unimplemented_models
64
import tableauserverclient as TSC
75

86
import pytest
97

108

11-
# ensure that all models can be instantiated
12-
def instantiate_class(name: str, obj: Any):
9+
def is_concrete(obj: Any):
10+
return inspect.isclass(obj) and not inspect.isabstract(obj)
11+
12+
@pytest.mark.parametrize("class_name, obj", inspect.getmembers(TSC, is_concrete))
13+
def test_by_reflection(class_name, obj):
14+
instance = try_instantiate_class(class_name, obj)
15+
if instance:
16+
class_type = type(instance)
17+
if class_type in get_unimplemented_models():
18+
print(f"Class '{class_name}' has no repr defined, skipping test")
19+
return
20+
else:
21+
assert type(instance.__repr__).__name__ == "method"
22+
print(instance.__repr__.__name__)
23+
24+
25+
26+
# Instantiate a class if it doesn't require any parameters
27+
def try_instantiate_class(name: str, obj: Any) -> Any | None:
1328
# Get the constructor (init) of the class
1429
constructor = getattr(obj, "__init__", None)
1530
if constructor:
@@ -22,58 +37,12 @@ def instantiate_class(name: str, obj: Any):
2237
print(f"Class '{name}' requires the following parameters for instantiation:")
2338
for param in required_parameters:
2439
print(f"- {param.name}")
40+
return None
2541
else:
2642
print(f"Class '{name}' does not require any parameters for instantiation.")
2743
# Instantiate the class
2844
instance = obj()
29-
print(f"Instantiated: {name} -> {instance}")
45+
return instance
3046
else:
3147
print(f"Class '{name}' does not have a constructor (__init__ method).")
32-
33-
34-
not_yet_done = [
35-
"DQWItem",
36-
"UnpopulatedPropertyError",
37-
"FavoriteItem",
38-
"FileuploadItem",
39-
"FlowRunItem",
40-
"IntervalItem",
41-
"LinkedTaskItem",
42-
"LinkedTaskStepItem",
43-
"LinkedTaskFlowRunItem",
44-
"Permission",
45-
"SiteAuthConfiguration",
46-
"Resource",
47-
"TagItem",
48-
"ExtractItem",
49-
]
50-
51-
52-
class TestAllModels(TestCase):
53-
54-
# confirm that all models can be instantiated without params, and have __repr__ implemented
55-
# not all do have __repr__ yet: see above list 'not_yet_done'
56-
def test_repr_is_implemented(self):
57-
m = TSC_models
58-
for type_name in m.__dict__:
59-
if type_name in not_yet_done:
60-
continue
61-
model = getattr(m, type_name)
62-
if inspect.isclass(model):
63-
with self.subTest(type_name):
64-
self.assertTrue(hasattr(model, "__repr__"))
65-
self.assertEqual(type(model.__repr__).__name__, "function")
66-
67-
def is_concrete(obj: Any):
68-
return inspect.isclass(obj) and not inspect.isabstract(obj)
69-
70-
71-
@pytest.mark.parametrize("class_name, obj", inspect.getmembers(TSC, is_concrete))
72-
def test_by_reflection(class_name, obj):
73-
instantiate_class(class_name, obj)
74-
75-
76-
@pytest.mark.parametrize("model", _models.get_defined_models())
77-
def test_repr_is_implemented(model):
78-
print(model.__name__, type(model.__repr__).__name__)
79-
assert type(model.__repr__).__name__ == "function"
48+
return None

0 commit comments

Comments
 (0)