[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Added tests to generate_filename
commit d3110ed5baaa5fb11eb85c5a844041f41de780b8
Author: kudrom <kudrom@xxxxxxxxxx>
Date: Sun Jul 20 20:40:40 2014 +0200
Added tests to generate_filename
---
ooni/tests/test_utils.py | 40 +++++++++++++++++++++++++++++++++++++++-
ooni/utils/__init__.py | 3 +--
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/ooni/tests/test_utils.py b/ooni/tests/test_utils.py
index 7c2ab2d..c17235a 100644
--- a/ooni/tests/test_utils.py
+++ b/ooni/tests/test_utils.py
@@ -1,10 +1,20 @@
import os
from twisted.trial import unittest
-from ooni.utils import pushFilenameStack, log
+from ooni.utils import pushFilenameStack, log, generate_filename
class TestUtils(unittest.TestCase):
+ def setUp(self):
+ self.test_details = {
+ 'test_name': 'foo',
+ 'start_time': 1
+ }
+ self.extension = 'ext'
+ self.prefix = 'prefix'
+ self.basename = 'filename'
+ self.filename = 'filename.txe'
+
def test_pushFilenameStack(self):
basefilename = os.path.join(os.getcwd(), 'dummyfile')
f = open(basefilename, "w+")
@@ -33,3 +43,31 @@ class TestUtils(unittest.TestCase):
)
for encoded_logmsg, logmsg in logmsgs:
self.assertEqual(log.log_encode(logmsg), encoded_logmsg)
+
+ def test_generate_filename(self):
+ filename = generate_filename(self.test_details)
+ self.assertEqual(filename, 'foo-1')
+
+ def test_generate_filename_with_extension(self):
+ filename = generate_filename(self.test_details, extension=self.extension)
+ self.assertEqual(filename, 'foo-1.ext')
+
+ def test_generate_filename_with_prefix(self):
+ filename = generate_filename(self.test_details, prefix=self.prefix)
+ self.assertEqual(filename, 'prefix-foo-1')
+
+ def test_generate_filename_with_extension_and_prefix(self):
+ filename = generate_filename(self.test_details, prefix=self.prefix, extension=self.extension)
+ self.assertEqual(filename, 'prefix-foo-1.ext')
+
+ def test_generate_filename_with_filename(self):
+ filename = generate_filename(self.test_details, filename=self.filename)
+ self.assertEqual(filename, 'filename.txe')
+
+ def test_generate_filename_with_extension_and_filename(self):
+ filename = generate_filename(self.test_details, extension=self.extension, filename=self.filename)
+ self.assertEqual(filename, 'filename.ext')
+
+ def test_generate_filename_with_extension_and_basename(self):
+ filename = generate_filename(self.test_details, extension=self.extension, filename=self.basename)
+ self.assertEqual(filename, 'filename.ext')
diff --git a/ooni/utils/__init__.py b/ooni/utils/__init__.py
index 14fe667..f770c02 100644
--- a/ooni/utils/__init__.py
+++ b/ooni/utils/__init__.py
@@ -3,7 +3,7 @@ import random
import glob
import os
-from ooni import errors, otime
+from ooni import errors
class Storage(dict):
@@ -117,7 +117,6 @@ def generate_filename(testDetails, prefix=None, extension=None, filename=None):
"""
if filename is None:
test_name, start_time = testDetails['test_name'], testDetails['start_time']
- start_time = otime.epochToTimestamp(start_time)
suffix = "%s-%s" % (test_name, start_time)
basename = '%s-%s' % (prefix, suffix) if prefix is not None else suffix
final_filename = '%s.%s' % (basename, extension) if extension is not None else basename
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits