# HG changeset patch # User Laurent Peuch # Date 1558527781 -7200 # Node ID a74e7746954022fabe3d08539f504353366cdbf2 # Parent ca698656251ce76567aa8db01ed11fce186211bf [mod] move get_pdb to utils.py diff -r ca698656251c -r a74e77469540 cubicweb/cwctl.py --- a/cubicweb/cwctl.py Wed Oct 16 14:49:38 2019 +0200 +++ b/cubicweb/cwctl.py Wed May 22 14:23:01 2019 +0200 @@ -40,7 +40,7 @@ from logilab.common.configuration import merge_options from logilab.common.decorators import clear_cache -from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage +from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, utils from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS from cubicweb.server import set_debug from cubicweb.toolsutils import Command, rm, create_dir, underline_title @@ -102,16 +102,6 @@ return [drop_prefix(cube) for cube in cwcfg.available_cubes()] -def get_pdb(): - try: - import ipdb - except ImportError: - import pdb - return pdb - else: - return ipdb - - class InstanceCommand(Command): """base class for command taking one instance id as arguments""" arguments = '' @@ -208,7 +198,7 @@ status = ex.code if status != 0 and self.config.pdb: - pdb = get_pdb() + pdb = utils.get_pdb() if traceback_ is not None: pdb.post_mortem(traceback_) diff -r ca698656251c -r a74e77469540 cubicweb/test/unittest_cwctl.py --- a/cubicweb/test/unittest_cwctl.py Wed Oct 16 14:49:38 2019 +0200 +++ b/cubicweb/test/unittest_cwctl.py Wed May 22 14:23:01 2019 +0200 @@ -24,7 +24,7 @@ from logilab.common.clcommands import CommandLine -from cubicweb import cwctl, server +from cubicweb import utils, server from cubicweb.cwctl import ListCommand, InstanceCommand from cubicweb.devtools.testlib import CubicWebTC from cubicweb.server.migractions import ServerMigrationHelper @@ -123,7 +123,7 @@ self.assertEqual(cm.exception.code, 0) test_instance.assert_called_with("some_instance") - @patch.object(cwctl, 'get_pdb') + @patch.object(utils, 'get_pdb') def test_pdb_not_called(self, get_pdb): # CWCTL will finish the program after that with self.assertRaises(SystemExit) as cm: @@ -132,7 +132,7 @@ get_pdb.assert_not_called() - @patch.object(cwctl, 'get_pdb') + @patch.object(utils, 'get_pdb') def test_pdb_called(self, get_pdb): post_mortem = get_pdb.return_value.post_mortem with self.assertRaises(SystemExit) as cm: diff -r ca698656251c -r a74e77469540 cubicweb/utils.py --- a/cubicweb/utils.py Wed Oct 16 14:49:38 2019 +0200 +++ b/cubicweb/utils.py Wed May 22 14:23:01 2019 +0200 @@ -565,6 +565,17 @@ return 'javascript: ' + PERCENT_IN_URLQUOTE_RE.sub(r'%25', javascript_code) +def get_pdb(): + "return ipdb if its installed, otherwise pdb" + try: + import ipdb + except ImportError: + import pdb + return pdb + else: + return ipdb + + logger = getLogger('cubicweb.utils') class QueryCache(object):