예제 #1
0
 def test_search_paths_not_created(self, expanduser, get_config_var):
     expanduser.return_value = self.tmpdir
     get_config_var.return_value = self.tmpdir
     runner = Runner()
     cwd = os.path.dirname(os.path.abspath(__file__))
     self.assertEquals(runner.search_paths(),
                       [os.path.join(cwd, 'modules')])
예제 #2
0
 def test_search_paths(self, isdir):
     isdir.return_value = True
     runner = Runner()
     cwd = os.path.dirname(os.path.abspath(foo.__file__))
     _cwd = os.path.join(cwd, 'modules')
     _user = os.path.join(os.path.expanduser('~'), '.local', 'libexec',
                          'foo-tools')
     _egg = os.path.join(cwd, 'libexec', 'foo-tools')
     _global = os.path.join(sysconfig.get_config_var('base'), 'libexec',
                            'foo-tools')
     self.assertEquals(runner.search_paths(), [_user, _cwd, _egg, _global])
예제 #3
0
 def test_run(self, modules):
     module = mock.Mock()
     modules.return_value = {'foo': module}
     runner = Runner()
     runner.parser = parser = mock.Mock()
     parser.parse_args.return_value = Namespace(foo='bar', bar=['baz'],
                                                _lol='hehe', xd=None,
                                                log_level='NOTSET',
                                                _module=module)
     with mock.patch.object(sys, 'argv', ['foo', 'bar', '--traceback']):
         runner.run()
     module.build_argparse.assert_called_once_with(runner.subparser)
     parser.parse_args.assert_called_once_with(['bar'])
     module.run.assert_called_once_with({'bar': 'baz', 'foo': 'bar',
                                         'log_level': '0', 'xd': ''})
예제 #4
0
 def test_duplicated_modules(self, search_paths):
     _subdir = os.path.join(self.tmpdir, 'modules')
     if not os.path.isdir(_subdir):
         os.makedirs(_subdir)
     foo = os.path.join(self.tmpdir, 'foo')
     with open(foo, 'w') as fp:
         print >> fp
     foo1 = os.path.join(self.tmpdir, 'foo')
     with open(foo1, 'w') as fp:
         print >> fp
     search_paths.return_value = [self.tmpdir, _subdir]
     runner = Runner()
     modules = runner.modules()
     self.assertIn('foo', modules)
     self.assertEquals(modules['foo'].fname, foo)
예제 #5
0
 def test_modules(self, search_paths):
     _subdir = os.path.join(self.tmpdir, 'modules')
     if not os.path.isdir(_subdir):
         os.makedirs(_subdir)
     foo = os.path.join(self.tmpdir, 'foo')
     with open(foo, 'w') as fp:
         print >> fp
     bar = os.path.join(self.tmpdir, 'bar')
     with open(bar, 'w') as fp:
         print >> fp
     search_paths.return_value = [self.tmpdir, _subdir]
     runner = Runner()
     modules = runner.modules()
     self.assertIn('foo', modules)
     self.assertIn('bar', modules)
예제 #6
0
 def test_ok(self, Runner):
     Runner.return_value = runner = mock.Mock()
     runner.run.return_value = 0
     self.assertEquals(main(), 0)
     Runner.assert_called_once_with()
     runner.run.assert_called_once_with()