Anonymous avatar Anonymous committed 9ec3cc5

add unit tests and docstring

Comments (0)

Files changed (2)

     ``check_for_duplicates``
         whether to check for duplicate entries when adding entries to the
         file (optional, default: ``False``).
+        
+    ``klass``
+        class which is used to instantiate the return value (optional,
+        default: ``None``, the return value with be a :class:`~polib.POFile`
+        instance).
     """
     return _pofile_or_mofile(pofile, 'pofile', **kwargs)
 
     ``check_for_duplicates``
         whether to check for duplicate entries when adding entries to the
         file (optional, default: ``False``).
+        
+    ``klass``
+        class which is used to instantiate the return value (optional,
+        default: ``None``, the return value with be a :class:`~polib.POFile`
+        instance).
     """
     return _pofile_or_mofile(mofile, 'mofile', **kwargs)
 
                 self.fhandle = codecs.open(pofile, 'rU', enc)
         else:
             self.fhandle = pofile.splitlines()
+
         klass = kwargs.get('klass')
         if klass is None:
             klass = POFile
             polib.unescape('\\\\t and \\\\n and \\\\r and \\\\" and \\\\\\\\'),
             '\\t and \\n and \\r and \\" and \\\\'
         )
+        
+    def test_pofile_with_subclass(self):
+        """
+        Test that the pofile function correctly returns an instance of the 
+        passed in class
+        """
+        class CustomPOFile(polib.POFile):
+            pass
+        
+        pofile = polib.pofile('tests/test_indented.po', klass=CustomPOFile)
+        self.assertEqual(pofile.__class__, CustomPOFile)
+        
+    def test_mofile_with_subclass(self):
+        """
+        Test that the mofile function correctly returns an instance of the 
+        passed in class
+        """
+        class CustomMOFile(polib.MOFile):
+            pass
+        
+        mofile = polib.mofile('tests/test_utf8.mo', klass=CustomMOFile)
+        self.assertEqual(mofile.__class__, CustomMOFile)     
 
 
 class TestBaseFile(unittest.TestCase):
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.