Beispiel #1
0
    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))
Beispiel #2
0
    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': '.'
            }),
        }))
Beispiel #3
0
    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': '.'}),
        }))
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
 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')
Beispiel #7
0
 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')
Beispiel #8
0
 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'}),
                      }))
Beispiel #9
0
 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'}),
     }))
Beispiel #10
0
 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'}),
                      }))
Beispiel #11
0
    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))
Beispiel #12
0
 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
Beispiel #13
0
 def test_finalize_env_others(self):
     sys.platform = 'others'
     self.assertEqual(finalize_env({}), {})
Beispiel #14
0
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()}
Beispiel #15
0
 def test_finalize_env_others(self):
     sys.platform = 'others'
     self.assertEqual(sorted(finalize_env({}).keys()), ['PATH'])