Commit 3696b59b authored by jvoisin's avatar jvoisin

Fix some pep8-related issues

parent 3ac3f353
......@@ -47,6 +47,11 @@ class GenericArchiveStripper(parser.GenericParser):
"""
return self.is_clean(list_unsupported=True)
def remove_all(self):
""" Virtual method to remove all compromising fields
"""
raise NotImplementedError
class ZipStripper(GenericArchiveStripper):
""" Represent a zip file
......
......@@ -84,6 +84,8 @@ class XMLParser(xml.sax.handler.ContentHandler): # pragma: no cover
def startElement(self, name, attrs):
""" Called when entering into xml tag
:param attrs: Attributes of the `nam` xml tag
:param name: Name of the xml tag
"""
self.between = True
self.key = name
......@@ -91,6 +93,7 @@ class XMLParser(xml.sax.handler.ContentHandler): # pragma: no cover
def endElement(self, name):
""" Called when exiting a xml tag
:param name: name of the element
"""
if name == 'format': # leaving a fileformat section
self.list.append(self.dict.copy())
......@@ -102,6 +105,7 @@ class XMLParser(xml.sax.handler.ContentHandler): # pragma: no cover
def characters(self, characters):
""" Concatenate the content between opening and closing tags
:param characters: content of the tag
"""
if self.between:
self.content += characters
......
......@@ -117,9 +117,9 @@ def main():
argparser = create_arg_parser()
args = argparser.parse_args()
#show help if: neiter list nor file argument given; no argument at
#all given or the list argument mixed with some other argument given
if (not args.list and not args.files) or (not len(sys.argv) > 1) or (args.list and len(sys.argv) > 2):
# show help if: neither list nor file argument given; no argument at
# all given or the list argument mixed with some other argument given
if not (args.list or args.files) or (not sys.argv) or (args.list and len(sys.argv) > 2):
argparser.print_help()
sys.exit(2)
......
......@@ -31,7 +31,7 @@ class CFile(GObject.Object):
"""
def __init__(self, filename, **kwargs):
self.file = mat.create_class_file(filename, 0, **kwargs)
self.file = mat.create_class_file(filename, False, **kwargs)
class GUI(object):
......@@ -160,15 +160,15 @@ class GUI(object):
""" Popup that display on double-click
metadata from a file
"""
metadataPopupListStore = self.builder.get_object('MetadataPopupListStore')
metadataPopupListStore.clear()
metadatapopupliststore = self.builder.get_object('MetadataPopupListStore')
metadatapopupliststore.clear()
if self.liststore[row][0].file.is_clean():
self.liststore[row][2] = _('Clean')
metadataPopupListStore.append([_('No metadata found'), ''])
metadatapopupliststore.append([_('No metadata found'), ''])
else:
self.liststore[row][2] = _('Dirty')
for i, j in self.liststore[row][0].file.get_meta().iteritems():
metadataPopupListStore.append([i, j])
metadatapopupliststore.append([i, j])
popup_metadata = self.builder.get_object('MetadataPopup')
title = self.liststore[row][0].file.basename
......@@ -284,8 +284,8 @@ non-anonymised) file to output archive'))
iterator = self.treeview.get_selection().get_selected_rows()[1]
if not iterator: # if nothing is selected : select everything
iterator = range(len(self.liststore))
task = func(iterator) # launch func() in an asynchronous way
GLib.idle_add(task.next)
sync_task = func(iterator) # launch func() in an asynchronous way
GLib.idle_add(sync_task.next)
def __invert(self, button, name):
""" Invert a preference state """
......@@ -295,7 +295,9 @@ non-anonymised) file to output archive'))
self.add2archive = not self.add2archive
def populate(self, filenames):
""" Append selected files by add_file to the self.liststore """
""" Append selected files by add_file to the self.liststore
:param filenames: selected files
"""
not_supported = []
for filename in filenames: # filenames : all selected files/folders
if os.path.isdir(filename): # if "filename" is a directory
......@@ -343,10 +345,10 @@ non-anonymised) file to output archive'))
vbox.pack_start(treeview, True, True, 0)
# Create columns
rendererText = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(_('Filename'), rendererText, text=0)
renderertext = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(_('Filename'), renderertext, text=0)
treeview.append_column(column)
column = Gtk.TreeViewColumn(_('Reason'), rendererText, text=1)
column = Gtk.TreeViewColumn(_('Reason'), renderertext, text=1)
treeview.append_column(column)
dialog.show_all()
......
......@@ -24,6 +24,7 @@ import libmat.strippers
class MatExtension(GObject.GObject, Nautilus.MenuProvider):
""" A nautilus extension, acting as a frontend to MAT, to clean metadata."""
def __init__(self):
logging.debug("nautilus-mat: initialising")
......@@ -58,7 +59,10 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider):
@staticmethod
def show_message(message, msg_type=Gtk.MessageType.INFO):
""" Helper function to show a message in a popup """
""" Helper function to show a message in a popup
:param msg_type: Type of the message to display
:param message: Message to display
"""
dialog = Gtk.MessageDialog(parent=None,
flags=Gtk.DialogFlags.MODAL,
type=msg_type,
......@@ -69,7 +73,10 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider):
return ret
def menu_activate_cb(self, menu, current_file):
""" Callback function, used to clean the file """
""" Callback function, used to clean the file
:param current_file: Name of the selected file
:param menu: Menu id from which the callback was activated. Unused.
"""
if file.is_gone():
return
......
......@@ -16,6 +16,7 @@ if os.path.exists('MANIFEST'):
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
......
......@@ -136,10 +136,11 @@ class TestUnsupported(test.MATTest):
tar.close()
proc = subprocess.Popen(['mat', tarpath], stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
self.assertTrue('It contains unsupported filetypes:' \
self.assertTrue('It contains unsupported filetypes:'
'\n- libtest.py\n- test.py\n- clitest.py\n'
in str(stdout))
class TestHelp(test.MATTest):
""" Test the different ways to trigger help """
def test_dash_h(self):
......@@ -164,6 +165,7 @@ class TestHelp(test.MATTest):
_, stderr = proc.communicate()
self.assertTrue(('usage: mat [-h]' and ' error: unrecognized arguments:') in stderr)
def get_tests():
""" Return every clitests"""
suite = unittest.TestSuite()
......
......@@ -14,6 +14,7 @@ import glob
import sys
import tempfile
import unittest
import subprocess
VERBOSITY = 15
......@@ -27,6 +28,7 @@ FILE_LIST = zip(clean, dirty)
try: # PDF render processing
import cairo
import gi
gi.require_version('Poppler', '0.18')
from gi.repository import Poppler
import pdfrw
......@@ -42,9 +44,10 @@ except ImportError:
try: # exiftool
subprocess.check_output(['exiftool', '-ver'])
except:
except OSError:
FILE_LIST.remove(('clean é.tif', 'dirty é.tif'))
class MATTest(unittest.TestCase):
"""
Parent class of all test-functions
......@@ -84,26 +87,28 @@ def run_all_tests():
"""
import clitest
import libtest
SUITE = unittest.TestSuite()
SUITE.addTests(clitest.get_tests())
SUITE.addTests(libtest.get_tests())
suite = unittest.TestSuite()
suite.addTests(clitest.get_tests())
suite.addTests(libtest.get_tests())
return unittest.TextTestRunner(verbosity=VERBOSITY).run(suite).wasSuccessful()
return unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful()
def set_local():
''' Monkey patch pathes to run the testsuite on the _local_
""" Monkey patch pathes to run the testsuite on the _local_
version of MAT. See `run_all_tests` for more information about
what pathes we're changing and why.
'''
"""
os.environ['PATH'] = '..:' + os.environ['PATH']
sys.path.append('..')
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='MAT testsuite')
parser.add_argument('-s', '--system', action='store_true',
help='Test the system-wide version of mat')
help='Test the system-wide version of mat')
if parser.parse_args().system is False:
set_local()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment