Blob Blame Raw
From b5fe1641a0dff0fe9ac9833efef907bac0f81c21 Mon Sep 17 00:00:00 2001
From: Scott K Logan <logans@cottsay.net>
Date: Sun, 14 Dec 2014 19:14:09 -0800
Subject: [PATCH] Make tests independent of CWD

Tests currently rely on the CWD being the project root
---
 test/local/test_config.py      | 8 +++++---
 test/local/test_config_yaml.py | 6 ++++--
 test/local/test_interation.py  | 4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/test/local/test_config.py b/test/local/test_config.py
index ce6d236..254763f 100644
--- a/test/local/test_config.py
+++ b/test/local/test_config.py
@@ -41,6 +41,8 @@
 
 from . import mock_client
 
+_test_root = os.path.dirname(os.path.dirname(__file__))
+
 
 class MockVcsConfigElement(wstool.config_elements.VCSConfigElement):
 
@@ -102,9 +104,9 @@ def test_init(self):
         self.assertEqual(install_path, config.get_base_path())
         self.assertEqual([], config.get_config_elements())
         config = Config([PathSpec("foo"),
-                         PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
-                         PathSpec(os.path.join("test", "example_dirs", "ros")),
-                         PathSpec(os.path.join("test", "example_dirs", "roscpp")),
+                         PathSpec(os.path.join(_test_root, "example_dirs", "ros_comm")),
+                         PathSpec(os.path.join(_test_root, "example_dirs", "ros")),
+                         PathSpec(os.path.join(_test_root, "example_dirs", "roscpp")),
                          PathSpec("bar")],
                         ".",
                         None)
diff --git a/test/local/test_config_yaml.py b/test/local/test_config_yaml.py
index a6edcde..a6da357 100644
--- a/test/local/test_config_yaml.py
+++ b/test/local/test_config_yaml.py
@@ -42,11 +42,13 @@
     get_path_spec_from_yaml, get_yaml_from_uri, get_path_specs_from_uri, \
     PathSpec, aggregate_from_uris
 
+_test_root = os.path.dirname(os.path.dirname(__file__))
+
 
 class YamlIO_Test(unittest.TestCase):
 
     def test_get_yaml_from_uri_from_file(self):
-        filename = os.path.join("test", "example.yaml")
+        filename = os.path.join(_test_root, "example.yaml")
         yamlstr = get_yaml_from_uri(filename)
 
         self.assertTrue("text" in yamlstr)
@@ -57,7 +59,7 @@ def test_get_yaml_from_uri_from_file(self):
         # invalid
         try:
             yaml = get_yaml_from_uri(
-                os.path.join("test", "example-broken.yaml"))
+                os.path.join(_test_root, "example-broken.yaml"))
         except MultiProjectException:
             pass
         try:
diff --git a/test/local/test_interation.py b/test/local/test_interation.py
index 108d466..e84b35b 100644
--- a/test/local/test_interation.py
+++ b/test/local/test_interation.py
@@ -72,7 +72,7 @@ def test_twice_with_relpath(self):
 
         self.rel_uri_rosinstall = os.path.join(self.test_root_path, "rel_uri.rosinstall")
         _create_yaml_file([_create_config_elt_dict("git", "ros", self.ros_path),
-                           _create_config_elt_dict("git", "gitrepo", os.path.relpath(self.git_path))],
+                           _create_config_elt_dict("git", "gitrepo", os.path.relpath(self.git_path, self.directory))],
                           self.rel_uri_rosinstall)
 
         config = wstool.multiproject_cmd.get_config(self.directory, [self.rel_uri_rosinstall, self.ros_path])
@@ -85,7 +85,7 @@ def test_twice_with_relpath(self):
 
         self.rel_uri_rosinstall2 = os.path.join(self.test_root_path, "rel_uri.wstool2")
         # switch URIs to confuse config
-        _create_yaml_file([_create_config_elt_dict("git", "ros", os.path.relpath(self.git_path)),
+        _create_yaml_file([_create_config_elt_dict("git", "ros", os.path.relpath(self.git_path, self.directory)),
                            _create_config_elt_dict("git", "gitrepo", self.ros_path)],
                           self.rel_uri_rosinstall2)