From 8b371bfc276d18b1b3d0dc7f6999ec3e0b3ea1ea Mon Sep 17 00:00:00 2001 From: IAlibay Date: Tue, 14 Jul 2020 17:48:01 +0100 Subject: [PATCH 01/12] Basic fixes --- propka/input.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/propka/input.py b/propka/input.py index 8d70a55..1cc7d74 100644 --- a/propka/input.py +++ b/propka/input.py @@ -23,7 +23,7 @@ def open_file_for_reading(input_file): then will attempt fseek(0). """ try: - input_file.fseek(0) + input_file.seek(0) return input_file except AttributeError: pass @@ -53,7 +53,7 @@ def read_molecule_file(input_file, mol_container): # input is a pdb file. read in atoms and top up containers to make # sure that all atoms are present in all conformations conformations, conformation_names = read_pdb( - input_path, mol_container.version.parameters, mol_container) + input_file, mol_container.version.parameters, mol_container) if len(conformations) == 0: str_ = ('Error: The pdb file does not seems to contain any ' 'molecular conformations') From dfc55c1f9aaa71e160c4e8b388d13081073fe063 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Tue, 14 Jul 2020 18:47:10 +0100 Subject: [PATCH 02/12] Adds option to read file streams --- propka/input.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/propka/input.py b/propka/input.py index 1cc7d74..2f425fe 100644 --- a/propka/input.py +++ b/propka/input.py @@ -35,18 +35,29 @@ def open_file_for_reading(input_file): return file_ -def read_molecule_file(input_file, mol_container): +def read_molecule_file(input_file, mol_container, filename=None): """Read input file (PDB or PROPKA) for a molecular container Args input_file: input file to read mol_container: MolecularContainer object + filename: str, optional input filename when using a filestream Returns updated MolecularContainer object Raises ValuError if invalid input given """ - input_path = Path(input_file) + try: + input_path = Path(input_file) + except TypeError: + try: + input_path = Path(filename) + except TypeError: + errmsg = ("Path of provided input_file could not be determined " + "if passing a stream-like object, please provide an " + "appropriate string for the filename argument.") + raise TypeError(errmsg) from None + mol_container.name = input_path.stem input_file_extension = input_path.suffix if input_file_extension.lower() == '.pdb': From 24ea1ea835e499ed3f11d1dba0dfaea4a1faf105 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Tue, 14 Jul 2020 18:55:47 +0100 Subject: [PATCH 03/12] Adds some basic file-like object tests --- tests/test_basic_regression.py | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/test_basic_regression.py b/tests/test_basic_regression.py index 54c41f5..078ba1c 100644 --- a/tests/test_basic_regression.py +++ b/tests/test_basic_regression.py @@ -152,3 +152,66 @@ def test_regression(pdb, options, tmp_path): run_propka(options, pdb_path, tmp_path) if ref_path is not None: compare_output(pdb, tmp_path, ref_path) + + +def run_propka_stream(options, input_file, tmp_path): + """Run PROPKA software. + + Args: + options: list of PROPKA options + input_file: file-like PDB object + tmp_path: path for working directory + """ + options += [input_file.name] + args = loadOptions(options) + try: + _LOGGER.warning( + "Working in tmpdir {0:s} because of PROPKA file output; " + "need to fix this.".format(str(tmp_path))) + cwd = Path.cwd() + os.chdir(tmp_path) + parameters = read_parameter_file(args.parameters, Parameters()) + molecule = MolecularContainer(parameters, args) + molecule = read_molecule_file(input_file, molecule, + filename=input_file.name) + molecule.calculate_pka() + molecule.write_pka() + if args.generate_propka_input: + molecule.write_propka() + finally: + os.chdir(cwd) + + +@pytest.mark.parametrize("pdb, options", [ + pytest.param("1FTJ-Chain-A", [], id="1FTJ-Chain-A: no options"), + pytest.param('1HPX', [], id="1HPX: no options"), + pytest.param('4DFR', [], id="4DFR: no options"), + pytest.param('3SGB', [], id="3SGB: no options"), + pytest.param('3SGB-subset', [ + "--titrate_only", + "E:17,E:18,E:19,E:29,E:44,E:45,E:46,E:118,E:119,E:120,E:139"], + id="3SGB: --titrate_only"), + pytest.param('1HPX-warn', ['--quiet'], id="1HPX-warn: --quiet")]) +def test_filestream_regression(pdb, options, tmp_path): + """Basic regression but using streams for the input PDB file""" + path_dict = get_test_dirs() + ref_path = path_dict["results"] / ("{0:s}.dat".format(pdb)) + if ref_path.is_file(): + ref_path = ref_path.resolve() + else: + _LOGGER.warning("Missing results file for comparison: {0:s}".format( + str(ref_path))) + ref_path = None + pdb_path = path_dict["pdbs"] / ("{0:s}.pdb".format(pdb)) + if pdb_path.is_file(): + pdb_path = pdb_path.resolve() + input_file = open(pdb_path) + else: + errstr = "Missing PDB file: {0:s}".format(pdb_path) + raise FileNotFoundError(errstr) + tmp_path = Path(tmp_path).resolve() + + run_propka_stream(options, input_file, tmp_path) + + if ref_path is not None: + compare_output(pdb, tmp_path, ref_path) From 0b57c63bbe86a8b46589b63b52c7c3fbdcf357d5 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Tue, 14 Jul 2020 19:01:12 +0100 Subject: [PATCH 04/12] close the file --- tests/test_basic_regression.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_basic_regression.py b/tests/test_basic_regression.py index 078ba1c..da8690e 100644 --- a/tests/test_basic_regression.py +++ b/tests/test_basic_regression.py @@ -215,3 +215,4 @@ def test_filestream_regression(pdb, options, tmp_path): if ref_path is not None: compare_output(pdb, tmp_path, ref_path) + input_file.close() From 4b0104cea9327e72f640b8ef25afb155bb085799 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 13:50:24 +0100 Subject: [PATCH 05/12] stringio tests --- propka/input.py | 4 +- tests/__init__.py | 1 + tests/test_basic_regression.py | 14 +++-- tests/test_streamio.py | 108 +++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_streamio.py diff --git a/propka/input.py b/propka/input.py index 2f425fe..2929ae3 100644 --- a/propka/input.py +++ b/propka/input.py @@ -20,7 +20,7 @@ def open_file_for_reading(input_file): Args: input_file: path to file or file-like object. If file-like object, - then will attempt fseek(0). + then will attempt seek(0). """ try: input_file.seek(0) @@ -36,7 +36,7 @@ def open_file_for_reading(input_file): def read_molecule_file(input_file, mol_container, filename=None): - """Read input file (PDB or PROPKA) for a molecular container + """Read input file or stream (PDB or PROPKA) for a molecular container Args input_file: input file to read diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/test_basic_regression.py b/tests/test_basic_regression.py index da8690e..c63785f 100644 --- a/tests/test_basic_regression.py +++ b/tests/test_basic_regression.py @@ -3,6 +3,7 @@ import os import re from pathlib import Path +from io import StringIO import pytest from numpy.testing import assert_almost_equal from propka.parameters import Parameters @@ -154,7 +155,7 @@ def test_regression(pdb, options, tmp_path): compare_output(pdb, tmp_path, ref_path) -def run_propka_stream(options, input_file, tmp_path): +def run_propka_stream(options, input_file, filename, tmp_path): """Run PROPKA software. Args: @@ -162,7 +163,7 @@ def run_propka_stream(options, input_file, tmp_path): input_file: file-like PDB object tmp_path: path for working directory """ - options += [input_file.name] + options += [filename] args = loadOptions(options) try: _LOGGER.warning( @@ -173,7 +174,7 @@ def run_propka_stream(options, input_file, tmp_path): parameters = read_parameter_file(args.parameters, Parameters()) molecule = MolecularContainer(parameters, args) molecule = read_molecule_file(input_file, molecule, - filename=input_file.name) + filename=filename) molecule.calculate_pka() molecule.write_pka() if args.generate_propka_input: @@ -205,14 +206,15 @@ def test_filestream_regression(pdb, options, tmp_path): pdb_path = path_dict["pdbs"] / ("{0:s}.pdb".format(pdb)) if pdb_path.is_file(): pdb_path = pdb_path.resolve() - input_file = open(pdb_path) + #input_file = open(pdb_path) + with open(pdb_path, 'r') as writer: + io_file = StringIO(writer.read()) else: errstr = "Missing PDB file: {0:s}".format(pdb_path) raise FileNotFoundError(errstr) tmp_path = Path(tmp_path).resolve() - run_propka_stream(options, input_file, tmp_path) + run_propka_stream(options, io_file, f"{pdb}.pdb", tmp_path) if ref_path is not None: compare_output(pdb, tmp_path, ref_path) - input_file.close() diff --git a/tests/test_streamio.py b/tests/test_streamio.py new file mode 100644 index 0000000..d5b49f2 --- /dev/null +++ b/tests/test_streamio.py @@ -0,0 +1,108 @@ +"""Tests for PROPKA stream io""" +import logging +from pathlib import Path +from io import StringIO +import pytest +from propka.parameters import Parameters +from propka.molecular_container import MolecularContainer +from propka.input import read_parameter_file, read_molecule_file +from propka.lib import loadOptions + +from .test_basic_regression import get_test_dirs, compare_output + + +_LOGGER = logging.getLogger(__name__) + + +def get_paths(pdb): + """Helper function to get the path to the input and reference files""" + path_dict = get_test_dirs() + ref_path = path_dict["results"] / ("{0:s}.dat".format(pdb)) + pdb_path = path_dict["pdbs"] / ("{0:s}.pdb".format(pdb)) + + return ref_path.resolve(), pdb_path.resolve() + + +def run_propka_stream(options, input_file, filename): + """Run PROPKA software. + + Args: + options: list of PROPKA options + input_file: file-like PDB object + filename: filename for the file-like PDB object + tmp_path: path for working directory + """ + options += [filename] + args = loadOptions(options) + parameters = read_parameter_file(args.parameters, Parameters()) + molecule = MolecularContainer(parameters, args) + molecule = read_molecule_file(input_file, molecule, filename) + molecule.calculate_pka() + molecule.write_pka() + if args.generate_propka_input: + molecule.write_propka() + + +@pytest.mark.parametrize("pdb, options", [ + pytest.param("1FTJ-Chain-A", [], id="1FTJ-Chain-A: no options"), + pytest.param('3SGB-subset', [ + "--titrate_only", + "E:17,E:18,E:19,E:29,E:44,E:45,E:46,E:118,E:119,E:120,E:139"], + id="3SGB: --titrate_only"), + pytest.param('1HPX-warn', ['--quiet'], id="1HPX-warn: --quiet"), +]) +def test_textio_filestream(tmpdir, pdb, options): + """Basic regression test using TextIO streams for the input PDB file""" + # Get the relevant paths + ref_path, pdb_path = get_paths(pdb) + filename = f"{pdb}.pdb" + + filestream = open(pdb_path, 'r') + + with tmpdir.as_cwd(): + run_propka_stream(options, filestream, filename) + compare_output(pdb, Path.cwd(), ref_path) + + filestream.close() + + +@pytest.mark.parametrize("pdb, options", [ + pytest.param("1FTJ-Chain-A", [], id="1FTJ-Chain-A: no options"), + pytest.param('3SGB-subset', [ + "--titrate_only", + "E:17,E:18,E:19,E:29,E:44,E:45,E:46,E:118,E:119,E:120,E:139"], + id="3SGB: --titrate_only"), + pytest.param('1HPX-warn', ['--quiet'], id="1HPX-warn: --quiet"), +]) +def test_stringio_filestream(tmpdir, pdb, options): + """Basic regression test using StringIO streams for the input PDB file""" + # Get the relevant paths + ref_path, pdb_path = get_paths(pdb) + filename = f"{pdb}.pdb" + + with open(pdb_path, 'r') as writer: + filestream = StringIO(writer.read()) + + with tmpdir.as_cwd(): + run_propka_stream(options, filestream, filename) + compare_output(pdb, Path.cwd(), ref_path) + + filestream.close() + + +def test_typerror_nofilename(tmpdir): + """Tests for raised TypeError when not passing a filename to + read_molecule_file and using a file-like object without a name""" + pdb = "1FTJ-Chain-A" + options = [] + + ref_path, pdb_path = get_paths(pdb) + + with open(pdb_path, 'r') as writer: + filestream = StringIO(writer.read()) + + with tmpdir.as_cwd(): + errmsg = "Path of provided input_file could not be determined" + with pytest.raises(TypeError, match=errmsg): + # default value of filename is None + run_propka_stream(options, filestream, filename=None) From f672c635a276d8d0de53e3e02ecff6ee93c2cc0c Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 14:23:06 +0100 Subject: [PATCH 06/12] adds usage docs for file-like objects --- propka/input.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/propka/input.py b/propka/input.py index 2929ae3..26e61d5 100644 --- a/propka/input.py +++ b/propka/input.py @@ -38,14 +38,39 @@ def open_file_for_reading(input_file): def read_molecule_file(input_file, mol_container, filename=None): """Read input file or stream (PDB or PROPKA) for a molecular container - Args + Args: input_file: input file to read mol_container: MolecularContainer object - filename: str, optional input filename when using a filestream - Returns + filename (str): optional input filename when using a filestream + + Returns: updated MolecularContainer object - Raises + + Raises: ValuError if invalid input given + + Examples: + There are two main cases for using ``read_molecule_file``. The first + (and most common) is to pass the input file (``input_file``) as a + string which gives the path of the molecule file to be read (here we + also pass a ``MoleculeContainer`` object named ``mol_container``). + + >>> read_molecule_file('test.pdb', mol_container) + + + The other use case is when passing a file-like object, e.g. a + ``StringIO`` class, instance as the input file. In order to decide how + to process ``input_file``, ``read_molecule_file`` requires a file name. + Since file-like objects do not usually have an associated file name, we + must pass a value to the ``filename`` argument. This helps recognise + the file type (based on the extension being either `.pdb` or + `.propka_input`) and also associates that given ``filename`` with the + input MolecularContainer object. + + >>> read_molecule_file(string_io_object, mol_container, + filename='test.pdb') + + """ try: input_path = Path(input_file) From e3e0dd9878500ad1952e1b166c565b9ceec971a8 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 14:24:15 +0100 Subject: [PATCH 07/12] fix docs --- propka/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/propka/input.py b/propka/input.py index 26e61d5..d9087f2 100644 --- a/propka/input.py +++ b/propka/input.py @@ -39,7 +39,7 @@ def read_molecule_file(input_file, mol_container, filename=None): """Read input file or stream (PDB or PROPKA) for a molecular container Args: - input_file: input file to read + input_file: input file or stream to read mol_container: MolecularContainer object filename (str): optional input filename when using a filestream From 720a20944039399dab8bf4312d5503b153b8b74a Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 17:44:47 +0100 Subject: [PATCH 08/12] streamlines read_molecule_file logic --- propka/input.py | 53 +++++++++++++++++++++--------------------- tests/test_streamio.py | 33 ++++++++++++++++++-------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/propka/input.py b/propka/input.py index d9087f2..de17149 100644 --- a/propka/input.py +++ b/propka/input.py @@ -35,13 +35,15 @@ def open_file_for_reading(input_file): return file_ -def read_molecule_file(input_file, mol_container, filename=None): +def read_molecule_file(filename: str, mol_container, stream=None): """Read input file or stream (PDB or PROPKA) for a molecular container Args: - input_file: input file or stream to read - mol_container: MolecularContainer object - filename (str): optional input filename when using a filestream + filename(str): name of input file. If not using a filestream via the + ``stream`` argument, should be a path to the file to be read. + mol_container: MolecularContainer object. + stream: optional filestream handle. If ``None``, then open + ``filename`` as a local file for reading. Returns: updated MolecularContainer object @@ -51,7 +53,7 @@ def read_molecule_file(input_file, mol_container, filename=None): Examples: There are two main cases for using ``read_molecule_file``. The first - (and most common) is to pass the input file (``input_file``) as a + (and most common) is to pass the input file (``filename``) as a string which gives the path of the molecule file to be read (here we also pass a ``MoleculeContainer`` object named ``mol_container``). @@ -59,39 +61,36 @@ def read_molecule_file(input_file, mol_container, filename=None): The other use case is when passing a file-like object, e.g. a - ``StringIO`` class, instance as the input file. In order to decide how - to process ``input_file``, ``read_molecule_file`` requires a file name. - Since file-like objects do not usually have an associated file name, we - must pass a value to the ``filename`` argument. This helps recognise - the file type (based on the extension being either `.pdb` or - `.propka_input`) and also associates that given ``filename`` with the - input MolecularContainer object. - - >>> read_molecule_file(string_io_object, mol_container, - filename='test.pdb') + ``StringIO`` class, instance. This is done by passing the object via + the ``stream`` argument. Since file-like objects do not usually have + an associated file name, an appropirate file name should be passed to + the ``filename`` argument. In this case, ``filename`` is not opened for + reading, but instead is used to help recognise the file type (based on + the extension being either `.pdb` or `.propka_input`) and also uses + that given ``filename`` to assign a name to the input + MolecularContainer object. + + >>> read_molecule_file('test.pdb', mol_container, + stream=string_io_object) """ - try: - input_path = Path(input_file) - except TypeError: - try: - input_path = Path(filename) - except TypeError: - errmsg = ("Path of provided input_file could not be determined " - "if passing a stream-like object, please provide an " - "appropriate string for the filename argument.") - raise TypeError(errmsg) from None - + input_path = Path(filename) mol_container.name = input_path.stem input_file_extension = input_path.suffix + + if stream is not None: + input_file = stream + else: + input_file = filename + if input_file_extension.lower() == '.pdb': # input is a pdb file. read in atoms and top up containers to make # sure that all atoms are present in all conformations conformations, conformation_names = read_pdb( input_file, mol_container.version.parameters, mol_container) if len(conformations) == 0: - str_ = ('Error: The pdb file does not seems to contain any ' + str_ = ('Error: The pdb file does not seem to contain any ' 'molecular conformations') raise ValueError(str_) mol_container.conformations = conformations diff --git a/tests/test_streamio.py b/tests/test_streamio.py index d5b49f2..869ae55 100644 --- a/tests/test_streamio.py +++ b/tests/test_streamio.py @@ -30,13 +30,12 @@ def run_propka_stream(options, input_file, filename): options: list of PROPKA options input_file: file-like PDB object filename: filename for the file-like PDB object - tmp_path: path for working directory """ options += [filename] args = loadOptions(options) parameters = read_parameter_file(args.parameters, Parameters()) molecule = MolecularContainer(parameters, args) - molecule = read_molecule_file(input_file, molecule, filename) + molecule = read_molecule_file(filename, molecule, stream=input_file) molecule.calculate_pka() molecule.write_pka() if args.generate_propka_input: @@ -90,9 +89,9 @@ def test_stringio_filestream(tmpdir, pdb, options): filestream.close() -def test_typerror_nofilename(tmpdir): - """Tests for raised TypeError when not passing a filename to - read_molecule_file and using a file-like object without a name""" +def test_valuerror_nofiletype(tmpdir): + """Tests for raised ValueError when an unknown filename is passed to + read_molecule_file""" pdb = "1FTJ-Chain-A" options = [] @@ -101,8 +100,22 @@ def test_typerror_nofilename(tmpdir): with open(pdb_path, 'r') as writer: filestream = StringIO(writer.read()) - with tmpdir.as_cwd(): - errmsg = "Path of provided input_file could not be determined" - with pytest.raises(TypeError, match=errmsg): - # default value of filename is None - run_propka_stream(options, filestream, filename=None) + errmsg = "Unknown input file type" + with pytest.raises(ValueError, match=errmsg): + run_propka_stream(options, filestream, filename="test.dat") + + +def test_valuerror_notpdb(tmpdir): + """Tests for raised ValueError when a stream object that isn't a PDB + is passed to read_molecule_file""" + pdb = "1FTJ-Chain-A" + options = [] + + ref_path, pdb_path = get_paths(pdb) + + with open(pdb_path, 'r') as writer: + filestream = StringIO() + + errmsg = "The pdb file does not seem to contain any " + with pytest.raises(ValueError, match=errmsg): + run_propka_stream(options, filestream, filename="test.pdb") From d70b1e6caa346a5600b9e6fcf632f04469af42ab Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 18:05:34 +0100 Subject: [PATCH 09/12] Removes unecessary tests --- tests/test_basic_regression.py | 64 ---------------------------------- 1 file changed, 64 deletions(-) diff --git a/tests/test_basic_regression.py b/tests/test_basic_regression.py index c63785f..45169f0 100644 --- a/tests/test_basic_regression.py +++ b/tests/test_basic_regression.py @@ -154,67 +154,3 @@ def test_regression(pdb, options, tmp_path): if ref_path is not None: compare_output(pdb, tmp_path, ref_path) - -def run_propka_stream(options, input_file, filename, tmp_path): - """Run PROPKA software. - - Args: - options: list of PROPKA options - input_file: file-like PDB object - tmp_path: path for working directory - """ - options += [filename] - args = loadOptions(options) - try: - _LOGGER.warning( - "Working in tmpdir {0:s} because of PROPKA file output; " - "need to fix this.".format(str(tmp_path))) - cwd = Path.cwd() - os.chdir(tmp_path) - parameters = read_parameter_file(args.parameters, Parameters()) - molecule = MolecularContainer(parameters, args) - molecule = read_molecule_file(input_file, molecule, - filename=filename) - molecule.calculate_pka() - molecule.write_pka() - if args.generate_propka_input: - molecule.write_propka() - finally: - os.chdir(cwd) - - -@pytest.mark.parametrize("pdb, options", [ - pytest.param("1FTJ-Chain-A", [], id="1FTJ-Chain-A: no options"), - pytest.param('1HPX', [], id="1HPX: no options"), - pytest.param('4DFR', [], id="4DFR: no options"), - pytest.param('3SGB', [], id="3SGB: no options"), - pytest.param('3SGB-subset', [ - "--titrate_only", - "E:17,E:18,E:19,E:29,E:44,E:45,E:46,E:118,E:119,E:120,E:139"], - id="3SGB: --titrate_only"), - pytest.param('1HPX-warn', ['--quiet'], id="1HPX-warn: --quiet")]) -def test_filestream_regression(pdb, options, tmp_path): - """Basic regression but using streams for the input PDB file""" - path_dict = get_test_dirs() - ref_path = path_dict["results"] / ("{0:s}.dat".format(pdb)) - if ref_path.is_file(): - ref_path = ref_path.resolve() - else: - _LOGGER.warning("Missing results file for comparison: {0:s}".format( - str(ref_path))) - ref_path = None - pdb_path = path_dict["pdbs"] / ("{0:s}.pdb".format(pdb)) - if pdb_path.is_file(): - pdb_path = pdb_path.resolve() - #input_file = open(pdb_path) - with open(pdb_path, 'r') as writer: - io_file = StringIO(writer.read()) - else: - errstr = "Missing PDB file: {0:s}".format(pdb_path) - raise FileNotFoundError(errstr) - tmp_path = Path(tmp_path).resolve() - - run_propka_stream(options, io_file, f"{pdb}.pdb", tmp_path) - - if ref_path is not None: - compare_output(pdb, tmp_path, ref_path) From dd7434fc372c3f637aef31faf2893adea6502531 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 18:26:26 +0100 Subject: [PATCH 10/12] remove unused import and fix error test --- tests/test_basic_regression.py | 1 - tests/test_streamio.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_basic_regression.py b/tests/test_basic_regression.py index 45169f0..9f45b5c 100644 --- a/tests/test_basic_regression.py +++ b/tests/test_basic_regression.py @@ -3,7 +3,6 @@ import os import re from pathlib import Path -from io import StringIO import pytest from numpy.testing import assert_almost_equal from propka.parameters import Parameters diff --git a/tests/test_streamio.py b/tests/test_streamio.py index 869ae55..ef08fee 100644 --- a/tests/test_streamio.py +++ b/tests/test_streamio.py @@ -113,8 +113,7 @@ def test_valuerror_notpdb(tmpdir): ref_path, pdb_path = get_paths(pdb) - with open(pdb_path, 'r') as writer: - filestream = StringIO() + filestream = StringIO() errmsg = "The pdb file does not seem to contain any " with pytest.raises(ValueError, match=errmsg): From c24f59b6d4957f2e48febe15af09ba1bd692f612 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 18:34:21 +0100 Subject: [PATCH 11/12] removes spurious empty line --- tests/test_basic_regression.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_basic_regression.py b/tests/test_basic_regression.py index 9f45b5c..54c41f5 100644 --- a/tests/test_basic_regression.py +++ b/tests/test_basic_regression.py @@ -152,4 +152,3 @@ def test_regression(pdb, options, tmp_path): run_propka(options, pdb_path, tmp_path) if ref_path is not None: compare_output(pdb, tmp_path, ref_path) - From 81e51c34bc402f271a9249783760958015206920 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 15 Jul 2020 19:34:33 +0100 Subject: [PATCH 12/12] remove unecessary tmpdir --- tests/test_streamio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_streamio.py b/tests/test_streamio.py index ef08fee..13b302b 100644 --- a/tests/test_streamio.py +++ b/tests/test_streamio.py @@ -89,7 +89,7 @@ def test_stringio_filestream(tmpdir, pdb, options): filestream.close() -def test_valuerror_nofiletype(tmpdir): +def test_valuerror_nofiletype(): """Tests for raised ValueError when an unknown filename is passed to read_molecule_file""" pdb = "1FTJ-Chain-A" @@ -105,7 +105,7 @@ def test_valuerror_nofiletype(tmpdir): run_propka_stream(options, filestream, filename="test.dat") -def test_valuerror_notpdb(tmpdir): +def test_valuerror_notpdb(): """Tests for raised ValueError when a stream object that isn't a PDB is passed to read_molecule_file""" pdb = "1FTJ-Chain-A"