[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Fix persistence tests



commit e893c41565345720997a6195a498e37a6a455039
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Jan 14 13:08:03 2020 -0800

    Fix persistence tests
    
    Nothing too interesting. Few files needed to be opened in bytes mode and a
    deprecated os function replaced...
    
      Traceback (most recent call last):
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_persistent.py", line 53, in setUp
          fakeArgs = ['-c', os.path.join(os.getcwdu(), '..', 'bridgedb.conf')]
      builtins.AttributeError: module 'os' has no attribute 'getcwdu'
    
    Test results changed as follows...
    
      before: FAILED (skips=109, failures=24, errors=349, successes=498)
      after:  FAILED (skips=109, failures=22, errors=318, successes=531)
---
 bridgedb/parse/options.py                   |  2 +-
 bridgedb/persistent.py                      | 11 ++++++++---
 bridgedb/test/test_persistent.py            |  2 +-
 bridgedb/test/test_persistentSaveAndLoad.py |  6 +++---
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/bridgedb/parse/options.py b/bridgedb/parse/options.py
index 0eeb79e..c32ada3 100644
--- a/bridgedb/parse/options.py
+++ b/bridgedb/parse/options.py
@@ -206,7 +206,7 @@ class BaseOptions(usage.Options):
             if rundir is not None:
                 gRundir = os.path.abspath(os.path.expanduser(rundir))
             else:
-                gRundir = os.getcwdu()
+                gRundir = os.getcwd()
         setRundir(gRundir)
 
         if not os.path.isdir(gRundir):  # pragma: no cover
diff --git a/bridgedb/persistent.py b/bridgedb/persistent.py
index 89d3dd4..3d52ec5 100644
--- a/bridgedb/persistent.py
+++ b/bridgedb/persistent.py
@@ -128,6 +128,11 @@ class State(jelly.Jellyable):
 
         :param string statefile: The filename of the statefile.
         """
+
+        if filename is None:
+          self._statefile = None
+          return
+
         filename = os.path.abspath(os.path.expanduser(filename))
         logging.debug("Setting statefile to '%s'" % filename)
         self._statefile = filename
@@ -173,8 +178,8 @@ class State(jelly.Jellyable):
         err = ''
 
         try:
-            if isinstance(statefile, str):
-                fh = open(statefile, 'r')
+            if isinstance(statefile, (str, bytes)):
+                fh = open(statefile, 'rb')
             elif not statefile.closed:
                 fh = statefile
         except (IOError, OSError) as error:  # pragma: no cover
@@ -209,7 +214,7 @@ class State(jelly.Jellyable):
 
         fh = None
         try:
-            fh = open(statefile, 'w')
+            fh = open(statefile, 'wb')
         except (IOError, OSError) as error:  # pragma: no cover
             logging.warn("Error writing state file to '%s': %s"
                          % (statefile, error))
diff --git a/bridgedb/test/test_persistent.py b/bridgedb/test/test_persistent.py
index 269cc86..21aa67f 100644
--- a/bridgedb/test/test_persistent.py
+++ b/bridgedb/test/test_persistent.py
@@ -50,7 +50,7 @@ class StateTest(unittest.TestCase):
         exec(compiled, configuration)
         config = persistent.Conf(**configuration)
 
-        fakeArgs = ['-c', os.path.join(os.getcwdu(), '..', 'bridgedb.conf')]
+        fakeArgs = ['-c', os.path.join(os.getcwd(), '..', 'bridgedb.conf')]
         options = MainOptions()
         options.parseOptions(fakeArgs)
 
diff --git a/bridgedb/test/test_persistentSaveAndLoad.py b/bridgedb/test/test_persistentSaveAndLoad.py
index d01a536..bcdcdd7 100644
--- a/bridgedb/test/test_persistentSaveAndLoad.py
+++ b/bridgedb/test/test_persistentSaveAndLoad.py
@@ -58,8 +58,8 @@ class StateSaveAndLoadTests(unittest.TestCase):
         self.assertNotIdentical(self.state, loadedState)
         self.assertNotEqual(self.state, loadedState)
 
-        self.assertEqual(self.state.__dict__.keys().sort(),
-                         loadedState.__dict__.keys().sort())
+        self.assertEqual(list(self.state.__dict__.keys()).sort(),
+                         list(loadedState.__dict__.keys()).sort())
 
     def savedStateAssertions(self, savedStatefile=None):
         self.assertTrue(os.path.isfile(str(self.state.statefile)))
@@ -148,7 +148,7 @@ class StateSaveAndLoadTests(unittest.TestCase):
                           self.state.load, 'quux.state')
 
     def test_load_with_statefile_opened(self):
-        fh = open('quux.state', 'w+')
+        fh = open('quux.state', 'wb+')
         self.assertRaises(persistent.MissingState, self.state.load, fh)
         fh.close()
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits