Changeset - 986efdcfaf64
[Not reviewed]
default
0 2 0
domruf - 9 years ago 2017-05-11 00:19:14
dominikruf@gmail.com
vcs: remove unused code and test of it

Neither git nor mercurial nodes have a _mimetype attribute. Only
test_nodes.test_mimetype monkey patches it and that to me seems just wrong.
Thus, remove that part and fix the test with some usefull assertions.

Found by pylint.
2 files changed with 7 insertions and 18 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/nodes.py
Show inline comments
 
@@ -315,18 +315,8 @@ class FileNode(Node):
 

	
 
    def get_mimetype(self):
 
        """
 
        Mimetype is calculated based on the file's content. If ``_mimetype``
 
        attribute is available, it will be returned (backends which store
 
        mimetypes or can easily recognize them, should set this private
 
        attribute to indicate that type should *NOT* be calculated).
 
        Mimetype is calculated based on the file's content.
 
        """
 
        if hasattr(self, '_mimetype'):
 
            if (isinstance(self._mimetype, (tuple, list,)) and
 
                len(self._mimetype) == 2):
 
                return self._mimetype
 
            else:
 
                raise NodeError('given _mimetype attribute must be an 2 '
 
                                'element list or tuple')
 

	
 
        mtype, encoding = mimetypes.guess_type(self.name)
 

	
kallithea/tests/vcs/test_nodes.py
Show inline comments
 
@@ -152,13 +152,11 @@ class NodeBasicTest(unittest.TestCase):
 
        py_node = FileNode('test.py')
 
        tar_node = FileNode('test.tar.gz')
 

	
 
        ext = 'CustomExtension'
 

	
 
        my_node2 = FileNode('myfile2')
 
        my_node2._mimetype = [ext]
 
        my_node2._content = 'foobar'
 

	
 
        my_node3 = FileNode('myfile3')
 
        my_node3._mimetype = [ext,ext]
 
        my_node3._content = '\0foobar'
 

	
 
        self.assertEqual(py_node.mimetype, mimetypes.guess_type(py_node.name)[0])
 
        self.assertEqual(py_node.get_mimetype(), mimetypes.guess_type(py_node.name))
 
@@ -166,10 +164,11 @@ class NodeBasicTest(unittest.TestCase):
 
        self.assertEqual(tar_node.mimetype, mimetypes.guess_type(tar_node.name)[0])
 
        self.assertEqual(tar_node.get_mimetype(), mimetypes.guess_type(tar_node.name))
 

	
 
        self.assertRaises(NodeError,my_node2.get_mimetype)
 
        self.assertEqual(my_node2.mimetype, 'text/plain')
 
        self.assertEqual(my_node2.get_mimetype(), ('text/plain', None))
 

	
 
        self.assertEqual(my_node3.mimetype,ext)
 
        self.assertEqual(my_node3.get_mimetype(),[ext,ext])
 
        self.assertEqual(my_node3.mimetype, 'application/octet-stream')
 
        self.assertEqual(my_node3.get_mimetype(), ('application/octet-stream', None))
 

	
 
class NodeContentTest(unittest.TestCase):
 

	
0 comments (0 inline, 0 general)