Skip to content

Commit

Permalink
Only support loading custom edges with Graph.from_g2o(), not the stan…
Browse files Browse the repository at this point in the history
…dalone function (#79)
  • Loading branch information
JeffLIrion committed Nov 11, 2023
1 parent a0a89d1 commit ba37eb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 2 additions & 4 deletions graphslam/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
_LOGGER = logging.getLogger(__name__)


def load_g2o(infile, custom_edge_types=None):
def load_g2o(infile):
r"""Load a graph from a .g2o file.
Parameters
----------
infile : str
The path to the .g2o file
custom_edge_types : list[type], None
A list of custom edge types, which must be subclasses of ``BaseEdge``
Returns
-------
Expand All @@ -30,7 +28,7 @@ def load_g2o(infile, custom_edge_types=None):
"""
_LOGGER.warning("load_g2o is deprecated; use Graph.load_g2o instead")
return Graph.load_g2o(infile, custom_edge_types)
return Graph.load_g2o(infile)


def load_g2o_r2(infile):
Expand Down
15 changes: 11 additions & 4 deletions tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def setUp(self):
"""Clear ``FAKE_FILE``."""
FAKE_FILE.clear()

def test_load_g2o(self):
"""Test the ``load_g2o()`` function."""
infile = os.path.join(os.path.dirname(__file__), "test_r2.g2o")
g = load_g2o(infile)
g2 = load_g2o_r2(infile)
self.assertTrue(g.equals(g2))

def test_load_g2o_r2(self):
"""Test the ``load_g2o_r2()`` function."""
infile = os.path.join(os.path.dirname(__file__), "test_r2.g2o")
Expand Down Expand Up @@ -107,7 +114,7 @@ def test_load_custom_edge_without_to_g2o_without_from_g2o(self):
g.to_g2o("test.g2o")

with mock.patch("graphslam.graph.open", open_fake_file):
g2 = load_g2o("test.g2o")
g2 = Graph.load_g2o("test.g2o", [EdgeWithoutToG2OWithFromG2O])
self.assertFalse(g.equals(g2))

def test_load_custom_edge_with_to_g2o_without_from_g2o(self):
Expand All @@ -123,7 +130,7 @@ def test_load_custom_edge_with_to_g2o_without_from_g2o(self):
g.to_g2o("test.g2o")

with mock.patch("graphslam.graph.open", open_fake_file):
g2 = load_g2o("test.g2o", [EdgeWithToG2OWithoutFromG2O])
g2 = Graph.load_g2o("test.g2o", [EdgeWithToG2OWithoutFromG2O])
self.assertFalse(g.equals(g2))

def test_load_custom_edge_without_to_g2o_with_from_g2o(self):
Expand All @@ -139,7 +146,7 @@ def test_load_custom_edge_without_to_g2o_with_from_g2o(self):
g.to_g2o("test.g2o")

with mock.patch("graphslam.graph.open", open_fake_file):
g2 = load_g2o("test.g2o", [EdgeWithoutToG2OWithFromG2O])
g2 = Graph.load_g2o("test.g2o", [EdgeWithoutToG2OWithFromG2O])
self.assertFalse(g.equals(g2))

def test_load_custom_edge_with_to_g2o_with_from_g2o(self):
Expand All @@ -155,5 +162,5 @@ def test_load_custom_edge_with_to_g2o_with_from_g2o(self):
g.to_g2o("test.g2o")

with mock.patch("graphslam.graph.open", open_fake_file):
g2 = load_g2o("test.g2o", [EdgeWithToG2OWithFromG2O])
g2 = Graph.load_g2o("test.g2o", [EdgeWithToG2OWithFromG2O])
self.assertTrue(g.equals(g2))

0 comments on commit ba37eb2

Please sign in to comment.