Skip to content

Commit dd8138e

Browse files
committed
Added tests
1 parent 1ec6d7d commit dd8138e

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@
5555
"**/assets": true,
5656
"**/dist": true,
5757
"**/*.code-search": true
58-
}
58+
},
59+
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "*test*.py"],
60+
"python.testing.pytestEnabled": false,
61+
"python.testing.unittestEnabled": true
5962
}

backend_tools/pull_scripts.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from onshape_api.endpoints import feature_studios
66
from featurescript import feature_studio
77
from featurescript.transform import transform
8-
from featurescript import conf
98
from robot_code.documents import BACKEND
109

1110

onshape_api/paths/paths.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __hash__(self) -> int:
4848
return hash(self.document_id)
4949

5050
def __eq__(self, other) -> bool:
51-
return isinstance(other, type(self)) and self.document_id == other.document_id
51+
return isinstance(other, DocumentPath) and self.document_id == other.document_id
5252

5353
def __str__(self) -> str:
5454
return DocumentPath.to_api_path(self)
@@ -111,7 +111,7 @@ def __hash__(self) -> int:
111111

112112
def __eq__(self, other) -> bool:
113113
return (
114-
isinstance(other, type(self))
114+
isinstance(other, InstancePath)
115115
and super().__eq__(other)
116116
and self.instance_id == other.instance_id
117117
and self.wvm == other.wvm
@@ -167,7 +167,7 @@ def __hash__(self) -> int:
167167

168168
def __eq__(self, other) -> bool:
169169
return (
170-
isinstance(other, type(self))
170+
isinstance(other, ElementPath)
171171
and self.__eq__(other)
172172
and self.element_id == other.element_id
173173
)
@@ -221,7 +221,7 @@ def __hash__(self) -> int:
221221

222222
def __eq__(self, other) -> bool:
223223
return (
224-
isinstance(other, type(self))
224+
isinstance(other, PartPath)
225225
and self.__eq__(other)
226226
and self.part_id == other.part_id
227227
)

tests/path_tests.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
3+
from onshape_api.paths.paths import DocumentPath, ElementPath, InstancePath
4+
5+
inst_path = InstancePath("1", "2")
6+
same_path = InstancePath("1", "2")
7+
8+
doc_path = DocumentPath("1")
9+
element_path = ElementPath("1", "2", "5")
10+
11+
12+
class TestPathMethods(unittest.TestCase):
13+
def test_basic_comparisons(self):
14+
self.assertTrue(inst_path == same_path)
15+
self.assertFalse(inst_path is same_path)
16+
17+
def test_eq(self):
18+
self.assertTrue(inst_path.__eq__(same_path))
19+
20+
def test_hash(self):
21+
self.assertTrue(inst_path.__hash__() == same_path.__hash__())
22+
23+
def test_in(self):
24+
self.assertTrue(inst_path in [same_path])
25+
self.assertTrue(inst_path in {same_path})
26+
27+
def test_conversions(self):
28+
self.assertFalse(inst_path == doc_path)
29+
self.assertFalse(inst_path == element_path)
30+
self.assertFalse(inst_path is element_path)
31+
self.assertFalse(doc_path is inst_path)
32+
33+
def test_in_conversions(self):
34+
self.assertFalse(doc_path in [inst_path])
35+
self.assertFalse(doc_path in {inst_path})
36+
self.assertFalse(inst_path in [element_path])
37+
self.assertFalse(inst_path in {element_path})

0 commit comments

Comments
 (0)