[tor-commits] [stem/master] Skipping tests that fail when run as root
atagar at torproject.org
atagar at torproject.org
Tue Mar 19 01:43:44 UTC 2013
commit 6862dc4994996e78ebf4516094c29aad66ceb524
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Mar 18 18:20:35 2013 -0700
Skipping tests that fail when run as root
Some of our integ tests rely on permission failures for files we lack access
to, or path expansions. Running as root causes these to fail. Caught by
Dererk...
https://trac.torproject.org/7925
---
test/integ/descriptor/reader.py | 15 ++++++++++++++-
test/integ/util/system.py | 13 +++++++++++++
2 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 59e9c8c..4f92343 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -4,6 +4,7 @@ Integration tests for stem.descriptor.reader.
from __future__ import with_statement
+import getpass
import os
import signal
import sys
@@ -123,6 +124,12 @@ class TestDescriptorReader(unittest.TestCase):
due to permissions.
"""
+ # test relies on being unable to read a file
+
+ if getpass.getuser() == 'root':
+ test.runner.skip(self, "(running as root)")
+ return
+
# Skip the test on windows, since you can only set the file's
# read-only flag with os.chmod(). For more information see...
# http://docs.python.org/library/os.html#os.chmod
@@ -472,8 +479,14 @@ class TestDescriptorReader(unittest.TestCase):
Listens for a file that's skipped because we lack read permissions.
"""
- if system.is_windows():
+ # test relies on being unable to read a file
+
+ if getpass.getuser() == 'root':
+ test.runner.skip(self, "(running as root)")
+ return
+ elif system.is_windows():
test.runner.skip(self, "(chmod not functional)")
+ return
test_path = test.runner.get_runner().get_test_dir("secret_file")
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 1528d05..7ad046d 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -387,6 +387,19 @@ class TestSystem(unittest.TestCase):
Exercises the expand_path() method with actual runtime data.
"""
+ # Some of the following tests get confused when ran as root. For instance,
+ # in my case...
+ #
+ # >>> os.path.expanduser("~")
+ # '/home/atagar'
+ #
+ # >>> os.path.expanduser("~root")
+ # '/root'
+
+ if getpass.getuser() == 'root':
+ test.runner.skip(self, "(running as root)")
+ return
+
self.assertEquals(os.getcwd(), stem.util.system.expand_path("."))
self.assertEquals(os.getcwd(), stem.util.system.expand_path("./"))
self.assertEquals(os.path.join(os.getcwd(), "foo"), stem.util.system.expand_path("./foo"))
More information about the tor-commits
mailing list