Michael Merickel
2018-10-15 dd3cc81f75dcb5ff96e0751653071722a15f46c2
commit | author | age
262cea 1 import unittest
dd3cc8 2 from . import dummy
262cea 3
CM 4 class TestPTweensCommand(unittest.TestCase):
5     def _getTargetClass(self):
6         from pyramid.scripts.ptweens import PTweensCommand
7         return PTweensCommand
8
9     def _makeOne(self):
10         cmd = self._getTargetClass()([])
678790 11         cmd.bootstrap = dummy.DummyBootstrap()
MM 12         cmd.setup_logging = dummy.dummy_setup_logging()
ba9313 13         cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'
262cea 14         return cmd
CM 15
16     def test_command_no_tweens(self):
17         command = self._makeOne()
18         command._get_tweens = lambda *arg: None
19         L = []
20         command.out = L.append
21         result = command.run()
d58614 22         self.assertEqual(result, 0)
262cea 23         self.assertEqual(L, [])
CM 24
25     def test_command_implicit_tweens_only(self):
26         command = self._makeOne()
27         tweens = dummy.DummyTweens([('name', 'item')], None)
28         command._get_tweens = lambda *arg: tweens
29         L = []
30         command.out = L.append
31         result = command.run()
d58614 32         self.assertEqual(result, 0)
262cea 33         self.assertEqual(
CM 34            L[0],
35            '"pyramid.tweens" config value NOT set (implicitly ordered tweens '
36             'used)')
37
38     def test_command_implicit_and_explicit_tweens(self):
39         command = self._makeOne()
40         tweens = dummy.DummyTweens([('name', 'item')], [('name2', 'item2')])
41         command._get_tweens = lambda *arg: tweens
42         L = []
43         command.out = L.append
44         result = command.run()
d58614 45         self.assertEqual(result, 0)
262cea 46         self.assertEqual(
CM 47            L[0],
48            '"pyramid.tweens" config value set (explicitly ordered tweens used)')
49
50     def test__get_tweens(self):
51         command = self._makeOne()
52         registry = dummy.DummyRegistry()
53         self.assertEqual(command._get_tweens(registry), None)
54
d29151 55 class Test_main(unittest.TestCase):
CM 56     def _callFUT(self, argv):
57         from pyramid.scripts.ptweens import main
58         return main(argv, quiet=True)
59
60     def test_it(self):
61         result = self._callFUT(['ptweens'])
d58614 62         self.assertEqual(result, 2)