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