gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18092 - in gnunet-update: gnunet_update test


From: gnunet
Subject: [GNUnet-SVN] r18092 - in gnunet-update: gnunet_update test
Date: Thu, 10 Nov 2011 12:14:57 +0100

Author: harsha
Date: 2011-11-10 12:14:57 +0100 (Thu, 10 Nov 2011)
New Revision: 18092

Added:
   gnunet-update/test/test_util.py
Modified:
   gnunet-update/gnunet_update/util.py
   gnunet-update/test/test_config.py
Log:
added unit test cases for util

Modified: gnunet-update/gnunet_update/util.py
===================================================================
--- gnunet-update/gnunet_update/util.py 2011-11-10 10:33:36 UTC (rev 18091)
+++ gnunet-update/gnunet_update/util.py 2011-11-10 11:14:57 UTC (rev 18092)
@@ -29,7 +29,7 @@
     ldd_ouput : Output of `ldd <program>' to identify dependencies
     splitted_input: Is the input already splitted into lines? Default is False
 
-    Returns a list of 2 element lists having the dependency name as the first
+    Returns a list of max 2 element lists having the dependency name as the 
first
     element and the path of the dependency as the second one
     """
     def strip(str):            # helper function for stripping white spaces

Modified: gnunet-update/test/test_config.py
===================================================================
--- gnunet-update/test/test_config.py   2011-11-10 10:33:36 UTC (rev 18091)
+++ gnunet-update/test/test_config.py   2011-11-10 11:14:57 UTC (rev 18092)
@@ -16,7 +16,7 @@
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 #
-# File:    gnunet_update/tests/test_config.py
+# File:    /test/test_config.py
 # Author:  Sree Harsha Totakura
 
 

Added: gnunet-update/test/test_util.py
===================================================================
--- gnunet-update/test/test_util.py                             (rev 0)
+++ gnunet-update/test/test_util.py     2011-11-10 11:14:57 UTC (rev 18092)
@@ -0,0 +1,116 @@
+# This file is part of GNUnet.
+# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING.  If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# File:    tests/test_util.py
+# Author:  Sree Harsha Totakura
+
+"""Test cases for gnunet_update/util.py."""
+
+import unittest
+import os
+import tempfile
+from textwrap import dedent
+
+import __init__
+import gnunet_update.util as util
+
+
+class TestUtil(unittest.TestCase):
+    
+    sample_ldd_output = \
+"""        linux-gate.so.1 =>  (0x00513000)
+        libncurses.so.5 => /lib/libncurses.so.5 (0x0047f000)
+        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00bb1000)
+        /lib/ld-linux.so.2 (0x00a8e000)
+"""
+
+    sample_ldconfig_output = \
+"""1049 libs found in cache `/etc/ld.so.cache'
+        libzephyr.so.4 (libc6) => /usr/lib/libzephyr.so.4
+        libz.so (libc6) => /usr/lib/libz.so
+        libthread_db.so.1 (libc6, hwcap: 0x8008000000008000, OS ABI: Linux 
2.6.15) => /lib/tls/i686/cmov/libthread_db.so.1
+        libx264.so.85 (libc6, hwcap: 0x0008000004000000) => 
/usr/lib/i686/sse2/libx264.so.85
+"""
+    sample_test_data = \
+"""Y3Q8PC9JbTAgMTYxIDAgUj4+Pj4vUm90YXRlIDAvVHJpbUJveFswLjAgMC4wIDU5NS4yNzYgNDE5
+LjUyOF0vVHlwZS9QYWdlPj4NZW5kb2JqDTE1MSAwIG9iag08PC9GaWx0ZXIvRmxhdGVEZWNvZGUv
+Rmlyc3QgNjQvTGVuZ3RoIDc2MS9OIDgvVHlwZS9PYmpTdG0+PnN0cmVhbQ0KaN60VllvEzEQ/it+
+BKHiY32tVFVKQlMqkYKalIKqPiyJSVZsdqPNBrX/nplxrt5pAFnu2HN5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iJvFTdb9tGDH/XX8G9nR5EHXnfQxBgtZOhGxKstYYCa/bg
+acrm1Y5bxUuH/vXjnZS6iLMBexkEnEgev/njtYuVhv4edPngvr+r2m9F9Nt9lQUuOeTggB1hIA/j
+UN1WH/7p6g3cyaXYU7Z3KSDryJFdcc7OYOTkjfPQEGpHiV2ARmNKkXxM0O+q9uVOw3JfvZJPjNBa
+McZg3Ofciu8PQMUngWNGbQ2BiYTWp+IlX+WzoYgSD7aVFSU+5TVqjsJGdOYp91mXCU10zwg0MtvM
+O0wunfLFgERgNFIKzwgeLYyV1sRT/miQUPtwKpjq2FYU0MgQnrANWXQ6ZQGjd88IxIBywEZmY09Y
+LeTvMvFX1Yuu0mjEdz7zYeI8kR+GsR/eH/5cb2HcVG3X5al0t6KutRB9aWumPoKZUCY/I/69DN+Q
+"""
+    def test_parse_ldd_output(self):
+        """Test ldd output parsing."""
+        expected_output = [
+            ['linux-gate.so.1', '(0x00513000)'],
+            ['libncurses.so.5', '/lib/libncurses.so.5'],
+            ['libc.so.6', '/lib/tls/i686/cmov/libc.so.6'],
+            ['/lib/ld-linux.so.2']
+            ]
+        # Test on sample_ldd_output without splitting lines
+        self.assertEqual(util.parse_ldd_output(self.sample_ldd_output),
+                         expected_output)
+        # Test on sample_ldd_output wih splitted lines
+        
self.assertEqual(util.parse_ldd_output(self.sample_ldd_output.splitlines(),
+                                               splitted_input=True),
+                         expected_output)
+
+    def test_parse_ldconfig_output(self):
+        """Test ldconfig output parsing."""
+        expected_output = [
+            ['libzephyr.so.4','/usr/lib/libzephyr.so.4'],
+            ['libz.so', '/usr/lib/libz.so'],
+            ['libthread_db.so.1','/lib/tls/i686/cmov/libthread_db.so.1'],
+            ['libx264.so.85','/usr/lib/i686/sse2/libx264.so.85']
+            ]
+        # Test on sample_ldconfig_output
+        
self.assertEqual(util.parse_ldconfig_output(self.sample_ldconfig_output),
+                         expected_output)
+
+    def test_sha512_hexdigest(self):
+        """Test the sha512 digest."""
+        tmp_file = tempfile.NamedTemporaryFile(delete=False)
+        tmp_file.file.write(self.sample_test_data)
+        tmp_file.file.close()
+        # Assert that hash is calculated correctly
+        self.assertEqual(util.sha512_hexdigest(tmp_file.name),
+                         
'f70c7771776f76da0444cdb73aabb5d82b1db749eeb12266edf3d74c1377a339e36b414c33f1c9ea51213530571fb1f2007f738171e4900f6298753480ed8ba2')
+        # check if file is closed
+        self.assertEqual(tmp_file.file.closed, True)
+        os.remove(tmp_file.name)
+        
+
+if __name__ == '__main__':
+    unittest.main()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]