Browse Source

Pylint compliance

pull/189/head
Louis 9 years ago
parent
commit
1e1a25c203
  1. 2
      patacrep/tools/convert/__main__.py
  2. 47
      test/test_patatools/test_convert.py
  3. 3
      test/test_song/test_parser.py

2
patacrep/tools/convert/__main__.py

@ -67,7 +67,7 @@ def main(args=None):
with open(destname, "w") as destfile: with open(destname, "w") as destfile:
destfile.write(song.render()) destfile.write(song.render())
except ContentError as error: except ContentError:
LOGGER.error("Cannot parse file '%s'.", file) LOGGER.error("Cannot parse file '%s'.", file)
sys.exit(1) sys.exit(1)
except NotImplementedError: except NotImplementedError:

47
test/test_patatools/test_convert.py

@ -2,33 +2,33 @@
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
from pkg_resources import resource_filename
import contextlib import contextlib
import glob import glob
import os import os
import shutil
import unittest import unittest
from pkg_resources import resource_filename
from patacrep import files from patacrep import files
from patacrep.tools.__main__ import main as tools_main from patacrep.tools.__main__ import main as tools_main
from patacrep.encoding import open_read from patacrep.encoding import open_read
from patacrep.tools.convert.__main__ import main as convert_main from patacrep.tools.convert.__main__ import main as convert_main
from patacrep.songbook.__main__ import main as songbook_main
from .. import dynamic from .. import dynamic # pylint: disable=unused-import
from .. import logging_reduced from .. import logging_reduced
class TestConvert(unittest.TestCase, metaclass=dynamic.DynamicTest): class TestConvert(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Test of the "patatools convert" subcommand""" """Test of the "patatools convert" subcommand"""
def _system(self, main, args): @staticmethod
def _system(main, args):
try: try:
main(args) main(args)
except SystemExit as systemexit: except SystemExit as systemexit:
return systemexit.code return systemexit.code
return 0 return 0
def assertConvert(self, basename, in_format, out_format): def assertConvert(self, basename, in_format, out_format): # pylint: disable=invalid-name
"""Test of the "patatools convert" subcommand""" """Test of the "patatools convert" subcommand"""
sourcename = "{}.{}".format(basename, in_format) sourcename = "{}.{}".format(basename, in_format)
destname = "{}.{}".format(basename, out_format) destname = "{}.{}".format(basename, out_format)
@ -57,32 +57,29 @@ class TestConvert(unittest.TestCase, metaclass=dynamic.DynamicTest):
expected, expected,
) )
def assertFailConvert(self, basename, in_format, out_format): def assertFailConvert(self, basename, in_format, out_format): # pylint: disable=invalid-name
"""Test of the "patatools convert" subcommand""" """Test of the "patatools convert" subcommand"""
sourcename = "{}.{}".format(basename, in_format) sourcename = "{}.{}".format(basename, in_format)
destname = "{}.{}".format(basename, out_format) destname = "{}.{}".format(basename, out_format)
controlname = "{}.{}.control".format(sourcename, out_format)
for main, args in [ for main, args in [
(tools_main, ["patatools", "convert"]), (tools_main, ["patatools", "convert"]),
(convert_main, ["patatools-convert"]), (convert_main, ["patatools-convert"]),
]: ]:
with self.subTest(main=main, args=args): with self.subTest(main=main, args=args):
with self.chdir("test_convert_failure"): with self.chdir("test_convert_failure"):
with open_read(controlname) as controlfile: with logging_reduced():
with logging_reduced(): if os.path.exists(destname):
if os.path.exists(destname): os.remove(destname)
os.remove(destname) self.assertEqual(
self.assertEqual( self._system(main, args + [in_format, out_format, sourcename]),
self._system(main, args + [in_format, out_format, sourcename]), 1,
1, )
)
@staticmethod @staticmethod
@contextlib.contextmanager @contextlib.contextmanager
def chdir(*path): def chdir(*pathlist):
"""Context to temporarry change current directory, relative to this file directory """Temporary change current directory, relative to this file directory"""
""" with files.chdir(resource_filename(__name__, ""), *pathlist):
with files.chdir(resource_filename(__name__, ""), *path):
yield yield
@classmethod @classmethod
@ -103,7 +100,11 @@ class TestConvert(unittest.TestCase, metaclass=dynamic.DynamicTest):
@classmethod @classmethod
def _create_test_success(cls, base, in_format, out_format): def _create_test_success(cls, base, in_format, out_format):
"""Return a function testing that `base` compilation from `in_format` to `out_format` format. """Return a function testing conversion.
:param str base: Base name of the file to convert.
:param str in_format: Source format.
:param str out_format: Destination format.
""" """
test_parse_render = lambda self: self.assertConvert(base, in_format, out_format) test_parse_render = lambda self: self.assertConvert(base, in_format, out_format)
test_parse_render.__doc__ = ( test_parse_render.__doc__ = (
@ -113,10 +114,10 @@ class TestConvert(unittest.TestCase, metaclass=dynamic.DynamicTest):
@classmethod @classmethod
def _create_test_failure(cls, base, in_format, out_format): def _create_test_failure(cls, base, in_format, out_format):
"""Return a function testing that `base` compilation from `in_format` to `out_format` format. """Return a function testing failing conversions
""" """
test_parse_render = lambda self: self.assertFailConvert(base, in_format, out_format) test_parse_render = lambda self: self.assertFailConvert(base, in_format, out_format)
test_parse_render.__doc__ = ( test_parse_render.__doc__ = (
"Test that '{base}.{in_format}' raises an error when trying to convert it to '{out_format}'." "Test that '{base}.{in_format}' raises an error when trying to convert it to '{out_format}'." # pylint: disable=line-too-long
).format(base=os.path.basename(base), in_format=in_format, out_format=out_format) ).format(base=os.path.basename(base), in_format=in_format, out_format=out_format)
return test_parse_render return test_parse_render

3
test/test_song/test_parser.py

@ -48,8 +48,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
@staticmethod @staticmethod
@contextlib.contextmanager @contextlib.contextmanager
def chdir(*path): def chdir(*path):
"""Context to temporarry change current directory, relative to this file directory """Temporary change current directory, relative to this file directory"""
"""
with files.chdir(resource_filename(__name__, ""), *path): with files.chdir(resource_filename(__name__, ""), *path):
yield yield

Loading…
Cancel
Save