[tor-commits] [stem/master] Avoiding static /tmp usage

atagar at torproject.org atagar at torproject.org
Wed Feb 6 15:49:39 UTC 2013


commit 3687dde657dc8df40ffecadd45c4035ee3d44110
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Feb 6 07:41:30 2013 -0800

    Avoiding static /tmp usage
    
    Our tests had static /tmp paths at a couple places. Issue caught by Dererk and
    patch by Abhishek...
    
    https://trac.torproject.org/7926
---
 test/integ/process.py |   16 ++++++++--------
 test/runner.py        |    2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/test/integ/process.py b/test/integ/process.py
index fb9ec9c..a5af4c6 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -3,8 +3,10 @@ Tests the stem.process functions with various use cases.
 """
 
 import os
+import shutil
 import signal
 import subprocess
+import tempfile
 import time
 import unittest
 
@@ -17,8 +19,6 @@ import test.runner
 
 from test import mocking
 
-DATA_DIRECTORY = '/tmp/stem_integ'
-
 
 def _kill_process(process):
   if stem.prereq.is_python_26():
@@ -31,11 +31,11 @@ def _kill_process(process):
 
 class TestProcess(unittest.TestCase):
   def setUp(self):
-    if not os.path.exists(DATA_DIRECTORY):
-      os.makedirs(DATA_DIRECTORY)
+    self.data_directory = tempfile.mkdtemp()
 
   def tearDown(self):
     mocking.revert_mocking()
+    shutil.rmtree(self.data_directory)
 
   def test_launch_tor_with_config(self):
     """
@@ -58,7 +58,7 @@ class TestProcess(unittest.TestCase):
       config = {
         'SocksPort': '2777',
         'ControlPort': '2778',
-        'DataDirectory': DATA_DIRECTORY,
+        'DataDirectory': self.data_directory,
       },
       completion_percent = 5
     )
@@ -92,7 +92,7 @@ class TestProcess(unittest.TestCase):
 
     runner = test.runner.get_runner()
     start_time = time.time()
-    config = {'SocksPort': '2777', 'DataDirectory': DATA_DIRECTORY}
+    config = {'SocksPort': '2777', 'DataDirectory': self.data_directory}
     self.assertRaises(OSError, stem.process.launch_tor_with_config, config, runner.get_tor_command(), 100, None, 2)
     runtime = time.time() - start_time
 
@@ -128,7 +128,7 @@ class TestProcess(unittest.TestCase):
       config = {
         'SocksPort': '2777',
         'ControlPort': '2778',
-        'DataDirectory': DATA_DIRECTORY,
+        'DataDirectory': self.data_directory,
       },
       completion_percent = 5,
       take_ownership = True,
@@ -165,7 +165,7 @@ class TestProcess(unittest.TestCase):
       config = {
         'SocksPort': '2777',
         'ControlPort': '2778',
-        'DataDirectory': DATA_DIRECTORY,
+        'DataDirectory': self.data_directory,
       },
       completion_percent = 5,
       take_ownership = True,
diff --git a/test/runner.py b/test/runner.py
index 799e0d5..d9e0def 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -87,7 +87,7 @@ INTEG_RUNNER = None
 # control authentication options and attributes
 CONTROL_PASSWORD = "pw"
 CONTROL_PORT = 1111
-CONTROL_SOCKET_PATH = "/tmp/stem_integ/socket"
+CONTROL_SOCKET_PATH = tempfile.mkstemp()[1]
 
 Torrc = stem.util.enum.Enum(
   ("PORT", "ControlPort %i" % CONTROL_PORT),





More information about the tor-commits mailing list