diff --git a/package/CHANGELOG b/package/CHANGELOG index f1fc9cf0e4a..f75f30545d5 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -61,6 +61,7 @@ Enhancements * Added groupby method to Group objects. (PR #1112) Fixes + * Give correct error when the topology file format is not recognized (Issue #982) * Give correct error when file doesn't exist/ has bad permissions (Issue #981) * Improvement of analysis/waterdynamics module (Issue #935) * Removed MDAnalysis.analysis.PDBToBinaryTraj (Issue #1035) diff --git a/package/MDAnalysis/core/_get_readers.py b/package/MDAnalysis/core/_get_readers.py index ecc9dfdf02e..c998424833b 100644 --- a/package/MDAnalysis/core/_get_readers.py +++ b/package/MDAnalysis/core/_get_readers.py @@ -214,14 +214,13 @@ def get_parser_for(filename, format=None): return _PARSERS[format] except KeyError: raise ValueError( - "Cannot autodetect topology type for file '{0}' " - "(file extension could not be parsed).\n" - " You can use 'Universe(topology, ..., topology_format=FORMAT)' " - "to explicitly specify the format and\n" - " override automatic detection. Known FORMATs are:\n" - " {1}\n" - " See http://docs.mdanalysis.org/documentation_pages/topology/init.html#supported-topology-formats\n" - " For missing formats, raise an issue at " - "http://issues.mdanalysis.org".format(filename, _PARSERS.keys())) + "'{0}' isn't a valid topology format\n" + " You can use 'Universe(topology, ..., topology_format=FORMAT)' " + " to explicitly specify the format and\n" + " override automatic detection. Known FORMATs are:\n" + " {1}\n" + " See http://docs.mdanalysis.org/documentation_pages/topology/init.html#supported-topology-formats\n" + " For missing formats, raise an issue at " + " http://issues.mdanalysis.org".format(format, _PARSERS.keys())) diff --git a/testsuite/MDAnalysisTests/core/test_universe.py b/testsuite/MDAnalysisTests/core/test_universe.py index d268a98ae28..f5a062bbf20 100644 --- a/testsuite/MDAnalysisTests/core/test_universe.py +++ b/testsuite/MDAnalysisTests/core/test_universe.py @@ -75,6 +75,19 @@ def test_Universe_no_trajectory_AE(): assert_raises(AttributeError, getattr, u, 'trajectory') + @staticmethod + def test_Universe_topology_unrecognizedformat_VE(): + assert_raises(ValueError, mda.Universe, 'some.weird.not.pdb.but.converted.xtc') + + @staticmethod + def test_Universe_topology_unrecognizedformat_VE_msg(): + try: + mda.Universe('some.weird.not.pdb.but.converted.xtc') + except ValueError as e: + assert_('isn\'t a valid topology format' in e.args[0]) + else: + raise AssertionError + @staticmethod def test_Universe_topology_IE(): assert_raises(IOError,