# HG changeset patch # User domruf # Date 1494454754 -7200 # Node ID 986efdcfaf64f9cb52ac4d20ddf62ddfca6fcea7 # Parent e62b8685868319cf98c1c9641f659d95ba1c0fb4 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. diff -r e62b86858683 -r 986efdcfaf64 kallithea/lib/vcs/nodes.py --- a/kallithea/lib/vcs/nodes.py Wed May 10 23:14:12 2017 +0200 +++ b/kallithea/lib/vcs/nodes.py Thu May 11 00:19:14 2017 +0200 @@ -315,18 +315,8 @@ 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) diff -r e62b86858683 -r 986efdcfaf64 kallithea/tests/vcs/test_nodes.py --- a/kallithea/tests/vcs/test_nodes.py Wed May 10 23:14:12 2017 +0200 +++ b/kallithea/tests/vcs/test_nodes.py Thu May 11 00:19:14 2017 +0200 @@ -152,13 +152,11 @@ 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 @@ 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):