Commits

AJ R committed e4d42e9

Added file report test, plus some minor changes

Comments (0)

Files changed (3)

savReaderWriter/__init__.py

     import psyco
     psycoOk = True  # reading 66 % faster
 except ImportError:
-    print ("NOTE. Psyco module not found. Install this module " +
-           "to increase reader performance")
     psycoOk = False
 try:
     import numpy
     numpyOk = True
 except ImportError:
-    print ("NOTE. Numpy module not found. Install this module " +
-           "to use array slicing")
     numpyOk = False
+
 try:
     from cWriterow import cWriterow  # writing 66 % faster
     cWriterowOK = True
 except ImportError:
-    print ("NOTE. cWriterow module not found. Install this module " +
-            "to increase writer performance")
     cWriterowOK = False
 
 __author__ = "Albert-Jan Roskam" + " " + "@".join(["fomcl", "yahoo.com"])

savReaderWriter/unit_tests/test_SavReader_file_report.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+##############################################################################
+## Read a file and get some basic file info (reports)
+##############################################################################
+
+import unittest
+import sys
+import gocept.testing.assertion
+from savReaderWriter import *
+
+report_expected = """\
+**********************************************************************
+*File '../savReaderWriter/test_data/Employee data.sav' (24.32 kB) has 10 columns (variables) and 474 rows (4740 values)
+*The file was created with SPSS version: MS Windows Release 11.0 spssio32.dll (11.1.0)
+*The interface locale is: '...'
+*The interface mode is: Codepage (...)
+*The file encoding is: 'utf_8' (Code page: 65001)
+*File encoding and the interface encoding are compatible: ...
+*Your computer's locale is: '...' (Code page: ...)
+*The file contains the following variables:
+  01. id (F4 - numerical)
+  02. gender (A1 - string)
+  03. bdate (ADATE10 - numerical)
+  04. educ (F2 - numerical)
+  05. jobcat (F1 - numerical)
+  06. salary (DOLLAR8 - numerical)
+  07. salbegin (DOLLAR8 - numerical)
+  08. jobtime (F2 - numerical)
+  09. prevexp (F6 - numerical)
+  10. minority (F1 - numerical)
+**********************************************************************
+"""
+
+class test_SavReader_file_report(unittest.TestCase, gocept.testing.assertion.Ellipsis):
+    """Generate a file report"""
+
+    def setUp(self):
+        self.savFileName = "../savReaderWriter/test_data/Employee data.sav"
+
+    def test_SavReader_report_python2_and_3_str(self):
+        data = SavReader(self.savFileName)
+        with data:
+            report_got = str(data)
+        self.assertEllipsis(report_expected, report_got)
+
+    @unittest.skipIf(sys.version_info[0] > 2, "No 'unicode' in Python 3")
+    def test_SavReader_report_python2_unicode(self):
+        data = SavReader(self.savFileName)
+        with data:
+            report_got = unicode(data)
+            encoding = data.fileEncoding
+        self.assertEllipsis(report_expected.decode(encoding), report_got)
+
+    @unittest.skipIf(sys.version_info[0] == 2, "No bytes method in Python 2")
+    def test_SavReader_report_python3_bytes(self):
+        data = SavReader(self.savFileName)
+        with data:
+            encoding = data.fileEncoding
+            report_got = bytes(data, encoding)
+        self.assertEllipsis(report_expected.encode(encoding), report_got)
+
+if __name__ == "__main__":
+    unittest.main()
                    'Operating System :: Microsoft :: Windows',
                    'Operating System :: POSIX',
                    'Programming Language :: Cython',
-                   'Programming Language :: Python :: 2.6',
                    'Programming Language :: Python :: 2.7',
                    'Programming Language :: Python :: 3.3', 
                    'Programming Language :: Python :: Implementation :: CPython',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.