def test_bower_all_the_actions(self): remember_cwd(self) tmpdir = mkdtemp(self) os.chdir(tmpdir) stub_stdouts(self) stub_mod_call(self, cli) stub_base_which(self, which_bower) rt = self.setup_runtime() rt([ 'bower', '--install', '--view', '--init', 'example.package1', 'example.package2' ]) # inside stdout result = json.loads(sys.stdout.getvalue()) self.assertEqual(result['dependencies']['jquery'], '~3.1.0') self.assertEqual(result['dependencies']['underscore'], '~1.8.3') with open(join(tmpdir, 'bower.json')) as fd: result = json.load(fd) self.assertEqual(result['dependencies']['jquery'], '~3.1.0') self.assertEqual(result['dependencies']['underscore'], '~1.8.3') args, kwargs = self.call_args self.assertEqual(args, (['bower', 'install'], )) env = kwargs.pop('env', {}) self.assertEqual(kwargs, {}) # have to do both, due to that this is an actual integration # test and values will differ between environments self.assertEqual(finalize_env(env), finalize_env(env))
def test_set_node_path(self): stub_mod_call(self, cli) stub_base_which(self) node_path = mkdtemp(self) driver = cli.PackageManagerDriver(node_path=node_path, pkg_manager_bin='mgr') # ensure env is passed into the call. with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install() self.assertEqual(self.call_args, ((['mgr', 'install'], ), { 'env': finalize_env({'NODE_PATH': node_path}), })) # will be overridden by instance settings. with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install( env={ 'PATH': '.', 'MGR_ENV': 'dev', 'NODE_PATH': '/tmp/somewhere/else/node_mods', }) self.assertEqual(self.call_args, ((['mgr', 'install'], ), { 'env': finalize_env({ 'NODE_PATH': node_path, 'MGR_ENV': 'dev', 'PATH': '.' }), }))
def test_set_node_path(self): stub_mod_call(self, cli) stub_base_which(self) node_path = mkdtemp(self) driver = cli.PackageManagerDriver( node_path=node_path, pkg_manager_bin='mgr') # ensure env is passed into the call. with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install(['calmjs']) self.assertEqual(self.call_args, ((['mgr', 'install'],), { 'env': finalize_env({'NODE_PATH': node_path}), })) # will be overridden by instance settings. with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install(['calmjs'], env={ 'PATH': '.', 'MGR_ENV': 'dev', 'NODE_PATH': '/tmp/somewhere/else/node_mods', }) self.assertEqual(self.call_args, ((['mgr', 'install'],), { 'env': finalize_env( {'NODE_PATH': node_path, 'MGR_ENV': 'dev', 'PATH': '.'}), }))
def test_finalize_env_win32(self): sys.platform = 'win32' # when os.environ is empty or missing the required keys, the # values will be empty strings. os.environ = {} self.assertEqual(finalize_env({}), { 'PATH': '', 'PATHEXT': '', 'SYSTEMROOT': ''}) # should be identical with the keys copied os.environ['PATH'] = 'C:\\Windows' os.environ['PATHEXT'] = pathsep.join(('.com', '.exe', '.bat')) os.environ['SYSTEMROOT'] = 'C:\\Windows' self.assertEqual(finalize_env({}), os.environ)
def test_finalize_env_win32(self): sys.platform = 'win32' # when os.environ is empty or missing the required keys, the # values will be empty strings. os.environ = {} self.assertEqual(finalize_env({}), { 'APPDATA': '', 'PATH': '', 'PATHEXT': '', 'SYSTEMROOT': ''}) # should be identical with the keys copied os.environ['APPDATA'] = 'C:\\Users\\Guest\\AppData\\Roaming' os.environ['PATH'] = 'C:\\Windows' os.environ['PATHEXT'] = pathsep.join(('.com', '.exe', '.bat')) os.environ['SYSTEMROOT'] = 'C:\\Windows' self.assertEqual(finalize_env({}), os.environ)
def test_fork_exec_bytes(self): stdout, stderr = fork_exec( [sys.executable, '-c', 'import sys;print(sys.stdin.read())'], stdin=b'hello', env=finalize_env({}), ) self.assertEqual(stdout.strip(), b'hello')
def test_fork_exec_str(self): stdout, stderr = fork_exec( [sys.executable, '-c', 'import sys;print(sys.stdin.read())'], stdin=u'hello', env=finalize_env({}), ) self.assertEqual(stdout.strip(), u'hello')
def test_install_other_environ(self): stub_mod_call(self, cli) stub_base_which(self) driver = cli.PackageManagerDriver(pkg_manager_bin='mgr') with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install(env={'MGR_ENV': 'production'}) self.assertEqual(self.call_args, ((['mgr', 'install'], ), { 'env': finalize_env({'MGR_ENV': 'production'}), }))
def test_install_other_environ(self): stub_mod_call(self, cli) stub_base_which(self) stub_os_environ(self) # pop out NODE_PATH if available os.environ.pop('NODE_PATH', '') driver = cli.PackageManagerDriver(pkg_manager_bin='mgr') with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install(['calmjs'], env={ 'MGR_ENV': 'production'}) self.assertEqual(self.call_args, ((['mgr', 'install'],), { 'env': finalize_env({'MGR_ENV': 'production'}), }))
def test_install_other_environ(self): stub_mod_call(self, cli) stub_base_which(self) stub_os_environ(self) # pop out NODE_PATH if available os.environ.pop('NODE_PATH', '') driver = cli.PackageManagerDriver(pkg_manager_bin='mgr') with pretty_logging(stream=mocks.StringIO()): driver.pkg_manager_install(['calmjs'], env={'MGR_ENV': 'production'}) self.assertEqual(self.call_args, ((['mgr', 'install'], ), { 'env': finalize_env({'MGR_ENV': 'production'}), }))
def test_bower_install_integration(self): remember_cwd(self) tmpdir = mkdtemp(self) os.chdir(tmpdir) stub_mod_call(self, cli) stub_base_which(self, which_bower) rt = self.setup_runtime() rt(['bower', '--install', 'example.package1', 'example.package2']) with open(join(tmpdir, 'bower.json')) as fd: result = json.load(fd) self.assertEqual(result['dependencies']['jquery'], '~3.1.0') self.assertEqual(result['dependencies']['underscore'], '~1.8.3') # not foo install, but bower install since entry point specified # the actual runtime instance. args, kwargs = self.call_args self.assertEqual(args, (['bower', 'install'], )) env = kwargs.pop('env', {}) self.assertEqual(kwargs, {}) # have to do both, due to that this is an actual integration # test and values will differ between environments self.assertEqual(finalize_env(env), finalize_env(env))
def _gen_call_kws(self, **env): kw = {} if self.node_path is not None: env[NODE_PATH] = self.node_path if self.env_path is not None: # Initial assignment with check _check_isdir_assign_key(env, 'PATH', self.env_path) # then append the rest of it env['PATH'] = pathsep.join( [env.get('PATH', ''), os.environ.get('PATH', '')]) if self.working_dir: _check_isdir_assign_key( kw, 'cwd', self.working_dir, error_msg="current working directory left as default") kw['env'] = finalize_env(env) return kw
def test_finalize_env_others(self): sys.platform = 'others' self.assertEqual(finalize_env({}), {})
def webpack_env(node_path): env = { 'NODE_PATH': node_path, 'FORCE_COLOR': '1', } return {recode(k): recode(v) for k, v in finalize_env(env).items()}
def test_finalize_env_others(self): sys.platform = 'others' self.assertEqual(sorted(finalize_env({}).keys()), ['PATH'])