Skip to content

Commit

Permalink
Adding SNLPath methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex committed Oct 15, 2024
1 parent b74a4f2 commit 39d85ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/snl/python/snl_wrapping/PySNLPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,22 @@ ManagedTypeDeallocMethod(SNLPath)

GetBoolAttribute(Path, empty)
GetSizetAttribute(Path, size)
GetObjectMethod(Path, Instance, getHeadInstance)
GetObjectMethod(Path, Instance, getTailInstance)
GetObjectMethod(Path, Path, getHeadPath)
GetObjectMethod(Path, Path, getTailPath)

PyMethodDef PySNLPath_Methods[] = {
{ "empty", (PyCFunction)PySNLPath_empty, METH_NOARGS,
"Returns True if this path is empty"},
{ "getHeadInstance", (PyCFunction)PySNLPath_getHeadInstance, METH_NOARGS,
"Returns the head instance of this path"},
{ "getTailInstance", (PyCFunction)PySNLPath_getTailInstance, METH_NOARGS,
"Returns the tail instance of this path"},
{ "getHeadPath", (PyCFunction)PySNLPath_getHeadPath, METH_NOARGS,
"Returns the head path of this path"},
{ "getTailPath", (PyCFunction)PySNLPath_getTailPath, METH_NOARGS,
"Returns the tail path of this path"},
{ "size", (PyCFunction)PySNLPath_size, METH_NOARGS,
"Returns the size of this path"},
{NULL, NULL, 0, NULL} /* sentinel */
Expand Down
13 changes: 9 additions & 4 deletions test/snl/python/snl_wrapping/test_snlpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@ def testFunctions(self):
ins1 = snl.SNLInstance.create(self.top, self.model, "ins1")

path0 = snl.SNLPath()
print(path0)
self.assertIsNotNone(path0)
self.assertTrue(path0.empty())
self.assertEqual(0, path0.size())
self.assertEqual(snl.SNLPath(), path0.getHeadPath())
self.assertEqual(snl.SNLPath(), path0.getTailPath())
self.assertIsNone(path0.getHeadInstance())
self.assertIsNone(path0.getTailInstance())

path1 = snl.SNLPath(ins1)
self.assertIsNotNone(path1)
self.assertFalse(path1.empty())
self.assertEqual(1, path1.size())
self.assertEqual(snl.SNLPath(), path1.getHeadPath())
self.assertEqual(snl.SNLPath(), path1.getTailPath())
self.assertEqual(ins1, path1.getHeadInstance())
self.assertEqual(ins1, path1.getTailInstance())

path2 = snl.SNLPath(path1, ins2)
self.assertIsNotNone(path2)
self.assertFalse(path2.empty())
self.assertEqual(2, path2.size())
self.assertEqual(path1, path2.getHeadPath())
self.assertEqual(snl.SNLPath(ins2), path2.getTailPath())
self.assertEqual(ins1, path2.getHeadInstance())
self.assertEqual(ins2, path2.getTailInstance())

path3 = snl.SNLPath(ins2)
path4 = snl.SNLPath(ins1, path3)

with self.assertRaises(RuntimeError) as context: snl.SNLPath(path1)
with self.assertRaises(RuntimeError) as context: snl.SNLPath(path1, path2)
with self.assertRaises(RuntimeError) as context: snl.SNLPath(1, 1, 1)
Expand Down

0 comments on commit 39d85ba

Please sign in to comment.