Skip to content

Commit bf9c1c1

Browse files
committed
test: refactor extract method to module
1 parent ee96c95 commit bf9c1c1

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

Tests/AnnotationService_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import string
44
import unittest
55
from pathlib import Path
6-
from uuid import uuid1
76

7+
from Tests.Utils import generate_test_uuid
88
from TM1py.Objects import Annotation, Cube, Dimension, Element, Hierarchy
99
from TM1py.Services import TM1Service
1010

@@ -35,7 +35,7 @@ def setUp(self):
3535
Run before each test to create a cube with test annotations
3636
"""
3737
# Build Dimensions
38-
test_uuid = str(uuid1()).replace("-", "_")
38+
test_uuid = generate_test_uuid()
3939
self.dimension_names = (
4040
"TM1py_tests_annotations_dimension1_" + test_uuid,
4141
"TM1py_tests_annotations_dimension2_" + test_uuid,

Tests/ElementService_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
import copy
33
import unittest
44
from pathlib import Path
5-
from uuid import uuid1
65

76
from mdxpy import MdxBuilder
87

9-
from Tests.Utils import skip_if_no_pandas, skip_if_version_lower_than
8+
from Tests.Utils import (
9+
generate_test_uuid,
10+
skip_if_no_pandas,
11+
skip_if_version_lower_than,
12+
)
1013
from TM1py.Exceptions import TM1pyException, TM1pyRestException
1114
from TM1py.Objects import Dimension, Element, ElementAttribute, Hierarchy
1215
from TM1py.Services import TM1Service
@@ -27,7 +30,7 @@ def setUpClass(cls):
2730
cls.tm1 = TM1Service(**cls.config["tm1srv01"])
2831

2932
def setUp(self):
30-
dimension_uuid = str(uuid1()).replace("-", "_")
33+
dimension_uuid = generate_test_uuid()
3134
prefix = "TM1py_unittest_element"
3235
pure_dimension_name = f"{prefix}_dimension_{dimension_uuid}"
3336

Tests/Utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import functools
2+
from uuid import uuid1
23

34
from TM1py.Services.RestService import AuthenticationMode
45
from TM1py.Utils.Utils import verify_version
56

67

8+
def generate_test_uuid() -> str:
9+
"""
10+
Generate a unique identifier for test objects.
11+
12+
Creates a UUID-based string suitable for appending to TM1 object names
13+
to ensure test isolation and uniqueness.
14+
15+
:return: A unique identifier with hyphens replaced by underscores.
16+
:rtype: str
17+
"""
18+
test_uuid = str(uuid1()).replace("-", "_")
19+
return test_uuid
20+
21+
722
def skip_if_no_pandas(func):
823
"""
924
Checks whether pandas is installed and skips the test if not

0 commit comments

Comments
 (0)