22 import unittest |
22 import unittest |
23 from unittest.mock import patch, MagicMock |
23 from unittest.mock import patch, MagicMock |
24 |
24 |
25 from logilab.common.clcommands import CommandLine |
25 from logilab.common.clcommands import CommandLine |
26 |
26 |
27 from cubicweb import cwctl, server |
27 from cubicweb import utils, server |
28 from cubicweb.cwctl import ListCommand, InstanceCommand |
28 from cubicweb.cwctl import ListCommand, InstanceCommand |
29 from cubicweb.devtools.testlib import CubicWebTC |
29 from cubicweb.devtools.testlib import CubicWebTC |
30 from cubicweb.server.migractions import ServerMigrationHelper |
30 from cubicweb.server.migractions import ServerMigrationHelper |
31 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
31 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
32 from cubicweb.__pkginfo__ import version as cw_version |
32 from cubicweb.__pkginfo__ import version as cw_version |
121 with self.assertRaises(SystemExit) as cm: |
121 with self.assertRaises(SystemExit) as cm: |
122 self.CWCTL.run(["test", "some_instance"]) |
122 self.CWCTL.run(["test", "some_instance"]) |
123 self.assertEqual(cm.exception.code, 0) |
123 self.assertEqual(cm.exception.code, 0) |
124 test_instance.assert_called_with("some_instance") |
124 test_instance.assert_called_with("some_instance") |
125 |
125 |
126 @patch.object(cwctl, 'get_pdb') |
126 @patch.object(utils, 'get_pdb') |
127 def test_pdb_not_called(self, get_pdb): |
127 def test_pdb_not_called(self, get_pdb): |
128 # CWCTL will finish the program after that |
128 # CWCTL will finish the program after that |
129 with self.assertRaises(SystemExit) as cm: |
129 with self.assertRaises(SystemExit) as cm: |
130 self.CWCTL.run(["test", "some_instance"]) |
130 self.CWCTL.run(["test", "some_instance"]) |
131 self.assertEqual(cm.exception.code, 0) |
131 self.assertEqual(cm.exception.code, 0) |
132 |
132 |
133 get_pdb.assert_not_called() |
133 get_pdb.assert_not_called() |
134 |
134 |
135 @patch.object(cwctl, 'get_pdb') |
135 @patch.object(utils, 'get_pdb') |
136 def test_pdb_called(self, get_pdb): |
136 def test_pdb_called(self, get_pdb): |
137 post_mortem = get_pdb.return_value.post_mortem |
137 post_mortem = get_pdb.return_value.post_mortem |
138 with self.assertRaises(SystemExit) as cm: |
138 with self.assertRaises(SystemExit) as cm: |
139 self.CWCTL.run(["test_fail", "some_instance", "--pdb"]) |
139 self.CWCTL.run(["test_fail", "some_instance", "--pdb"]) |
140 self.assertEqual(cm.exception.code, 8) |
140 self.assertEqual(cm.exception.code, 8) |