class TestDirectorySearcher(unittest.TestCase): def setUp(self): self.root = os.path.join(os.path.dirname(__file__), 'bin') self.ds = DirectorySearcher(self.root) def test_search(self): executable = os.path.join(self.root, 'executable') self.assertEqual(self.ds.search('executable'), executable) def test_search_not_x(self): self.assertIsNone(self.ds.search('not-executable')) def test_search_not_exits(self): self.assertIsNone(self.ds.search('not-found'))
def run_ruby(command, *args, **kw): if '/' not in command: searcher = DirectorySearcher(GEM_HOME.joinpath('bin')) command = searcher.search(command) if not path(command).exists(): raise RuntimeError('command {} does not exist'.format(command)) env = dict(os.environ) env['GEM_HOME'] = GEM_HOME info('Running: GEM_HOME=%s ruby %s %s', GEM_HOME, command, ' '.join(args)) expected_returns = kw.get('expect', {0}) ruby = subprocess.Popen([which.ruby, command] + list(args), env=env) if not kw.get('background', False): rc = ruby.wait() debug('Command returned %s', rc) if expected_returns and rc not in expected_returns: raise RuntimeError('{} returned a unexpected {}'.format( command, rc )) return ruby
def setUp(self): self.root = os.path.join(os.path.dirname(__file__), 'bin') self.ds = DirectorySearcher(self.root)