예제 #1
0
 def test_get_bin_version_no_bin(self):
     stub_mod_check_output(self, cli, fake_error(OSError))
     stub_base_which(self)
     with pretty_logging(stream=mocks.StringIO()) as err:
         results = cli._get_bin_version('some_app')
     self.assertIn("failed to execute 'some_app'", err.getvalue())
     self.assertIsNone(results)
예제 #2
0
    def test_install_init_install_develop(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_yarn)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(
            dict(
                script_name='setup.py',
                script_args=['yarn', '--init', '--install', '--development'],
                name='foo',
            ))
        dist.parse_command_line()
        dist.run_commands()

        with open(os.path.join(tmpdir, 'package.json')) as fd:
            result = json.load(fd)

        self.assertEqual(
            result, {
                'dependencies': {
                    'jquery': '~1.11.0'
                },
                'devDependencies': {},
                'name': 'foo',
            })
        # Should still invoke install
        self.assertEqual(self.call_args[0],
                         ([which_yarn, 'install', '--production=false'], ))
예제 #3
0
    def test_install_no_init_nodevnoprod(self):
        # install implies init
        stub_mod_call(self, cli)
        stub_base_which(self, which_yarn)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(
            dict(
                script_name='setup.py',
                script_args=['yarn', '--install'],
                name='foo',
            ))
        dist.parse_command_line()
        dist.run_commands()

        with open(os.path.join(tmpdir, 'package.json')) as fd:
            result = json.load(fd)

        # The cli will still automatically write to that, as install
        # implies init.
        self.assertEqual(
            result, {
                'dependencies': {
                    'jquery': '~1.11.0'
                },
                'devDependencies': {},
                'name': 'foo',
            })
        self.assertEqual(self.call_args[0], ([which_yarn, 'install'], ))
예제 #4
0
파일: test_yarn.py 프로젝트: calmjs/calmjs
    def test_install_no_init_nodevnoprod(self):
        # install implies init
        stub_mod_call(self, cli)
        stub_base_which(self, which_yarn)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['yarn', '--install'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

        with open(os.path.join(tmpdir, 'package.json')) as fd:
            result = json.load(fd)

        # The cli will still automatically write to that, as install
        # implies init.
        self.assertEqual(result, {
            'dependencies': {'jquery': '~1.11.0'},
            'devDependencies': {},
            'name': 'foo',
        })
        self.assertEqual(self.call_args[0], ([which_yarn, 'install'],))
예제 #5
0
    def test_install_view(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_npm)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(
            dict(
                script_name='setup.py',
                script_args=['npm', '--install', '--view'],
                name='foo',
            ))
        dist.parse_command_line()
        dist.run_commands()

        with open(os.path.join(tmpdir, 'package.json')) as fd:
            result = json.load(fd)

        self.assertEqual(
            result, {
                'dependencies': {
                    'jquery': '~1.11.0'
                },
                'devDependencies': {},
                'name': 'foo',
            })
        self.assertEqual(self.call_args[0], ([which_npm, 'install'], ))
예제 #6
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': '.'
            }),
        }))
예제 #7
0
파일: test_cli.py 프로젝트: calmjs/calmjs
    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': '.'}),
        }))
예제 #8
0
    def test_npm_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_npm)
        rt = self.setup_runtime()
        rt([
            'foo', '--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, 'package.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 npm install since entry point specified
        # the actual runtime instance.
        self.assertEqual(self.call_args, (([which_npm, 'install'], ), {}))
예제 #9
0
 def test_set_binary_with_package(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='bower')
     # this will call ``bower install`` instead.
     driver.pkg_manager_install(['calmjs'])
     self.assertEqual(self.call_args[0], (['bower', 'install'], ))
예제 #10
0
    def test_pkg_manager_init_merge(self):
        self.setup_requirements_json()
        cwd = mkdtemp(self)
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr',
            pkgdef_filename='requirements.json',
            dep_keys=('require', ),
            working_dir=cwd,
        )
        target = join(cwd, 'requirements.json')
        with open(target, 'w') as fd:
            result = json.dump({"require": {"calmpy": "1.0.0"}}, fd)

        driver.pkg_manager_init('calmpy.pip', merge=True, overwrite=True)
        self.assertNotEqual(
            result, {
                "require": {
                    "calmpy": "1.0.0",
                    "setuptools": "25.1.6",
                },
                "name": "calmpy.pip",
            })

        stub_mod_call(self, cli)
        stub_base_which(self)
        with pretty_logging(stream=mocks.StringIO()):
            # ensure the return value is True, assuming successful
            self.assertTrue(
                driver.pkg_manager_install('calmpy.pip', overwrite=True))
예제 #11
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_get_bin_version_no_bin(self):
     stub_mod_check_output(self, cli, fake_error(OSError))
     stub_base_which(self)
     with pretty_logging(stream=mocks.StringIO()) as err:
         results = cli.get_bin_version('some_app')
     self.assertIn("failed to execute 'some_app'", err.getvalue())
     self.assertIsNone(results)
예제 #12
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_get_bin_version_longer(self):
     stub_mod_check_output(self, cli)
     stub_base_which(self)
     # tags are ignored for now.
     self.check_output_answer = b'version.11.200.345.4928-what'
     results = cli.get_bin_version('some_app')
     self.assertEqual(results, (11, 200, 345, 4928))
예제 #13
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_set_binary_with_package(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='bower')
     # this will call ``bower install`` instead.
     driver.pkg_manager_install(['calmjs'])
     self.assertEqual(self.call_args[0], (['bower', 'install'],))
예제 #14
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))
예제 #15
0
파일: test_cli.py 프로젝트: calmjs/calmjs
    def test_pkg_manager_init_merge(self):
        self.setup_requirements_json()
        cwd = mkdtemp(self)
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr', pkgdef_filename='requirements.json',
            dep_keys=('require',),
            working_dir=cwd,
        )
        target = join(cwd, 'requirements.json')
        with open(target, 'w') as fd:
            result = json.dump({"require": {"calmpy": "1.0.0"}}, fd)

        driver.pkg_manager_init('calmpy.pip', merge=True, overwrite=True)
        self.assertNotEqual(result, {
            "require": {
                "calmpy": "1.0.0",
                "setuptools": "25.1.6",
            },
            "name": "calmpy.pip",
        })

        stub_mod_call(self, cli)
        stub_base_which(self)
        with pretty_logging(stream=mocks.StringIO()):
            # ensure the return value is True, assuming successful
            self.assertTrue(
                driver.pkg_manager_install('calmpy.pip', overwrite=True))
예제 #16
0
 def test_get_bin_version_longer(self):
     stub_mod_check_output(self, cli)
     stub_base_which(self)
     # tags are ignored for now.
     self.check_output_answer = b'version.11.200.345.4928-what'
     results = cli._get_bin_version('some_app')
     self.assertEqual(results, (11, 200, 345, 4928))
예제 #17
0
 def test_install_arguments(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(args=('--pedantic', ))
     self.assertEqual(self.call_args,
                      ((['mgr', 'install', '--pedantic'], ), {}))
예제 #18
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_install_arguments(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(['calmjs'], args=('--pedantic',))
     self.assertEqual(
         self.call_args[0], (['mgr', 'install', '--pedantic'],))
예제 #19
0
 def test_paths_unset(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()
     args, kwargs = self.call_args
     self.assertNotIn('PATH', kwargs)
     self.assertNotIn('cwd', kwargs)
예제 #20
0
 def test_install_failure(self):
     stub_mod_call(self, cli, fake_error(IOError))
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     with pretty_logging(stream=mocks.StringIO()) as stderr:
         with self.assertRaises(IOError):
             driver.mgr_install()
     val = stderr.getvalue()
     self.assertIn("invocation of the 'mgr' binary failed", val)
예제 #21
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_install_failure(self):
     stub_mod_call(self, cli, fake_error(IOError))
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     with pretty_logging(stream=mocks.StringIO()) as stderr:
         with self.assertRaises(IOError):
             driver.mgr_install(['calmjs'])
     val = stderr.getvalue()
     self.assertIn("invocation of the 'mgr' binary failed", val)
예제 #22
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_paths_unset(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(['calmjs'])
     args, kwargs = self.call_args
     self.assertNotIn('PATH', kwargs)
     self.assertNotIn('cwd', kwargs)
예제 #23
0
 def test_env_path_not_exist(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     bad_path = '/no/such/path/for/sure/at/here'
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                       env_path=bad_path)
     with pretty_logging(stream=mocks.StringIO()):
         driver.pkg_manager_install()
     args, kwargs = self.call_args
     self.assertNotEqual(kwargs['env']['PATH'].split(pathsep)[0], bad_path)
예제 #24
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'}),
                      }))
예제 #25
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_get_bin_version_unexpected(self):
     stub_mod_check_output(self, cli)
     stub_base_which(self)
     self.check_output_answer = b'Nothing'
     with pretty_logging(stream=mocks.StringIO()) as err:
         results = cli.get_bin_version('some_app')
     self.assertIn(
         "encountered unexpected error while trying to find version of "
         "'some_app'", err.getvalue())
     self.assertIsNone(results)
예제 #26
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_set_binary_no_package(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='bower')
     with pretty_logging(stream=mocks.StringIO()) as fd:
         driver.pkg_manager_install()
         self.assertIn(
             "no package name supplied, "
             "not continuing with 'bower install'", fd.getvalue())
     self.assertIsNone(self.call_args)
예제 #27
0
 def test_set_binary_no_package(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='bower')
     with pretty_logging(stream=mocks.StringIO()) as fd:
         driver.pkg_manager_install()
         self.assertIn(
             "no package name supplied, "
             "not continuing with 'bower install'", fd.getvalue())
     self.assertIsNone(self.call_args)
예제 #28
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_env_path_not_exist(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     bad_path = '/no/such/path/for/sure/at/here'
     driver = cli.PackageManagerDriver(
         pkg_manager_bin='mgr', env_path=bad_path)
     with pretty_logging(stream=mocks.StringIO()):
         driver.pkg_manager_install(['calmjs'])
     args, kwargs = self.call_args
     self.assertNotEqual(kwargs['env']['PATH'].split(pathsep)[0], bad_path)
예제 #29
0
 def test_get_bin_version_unexpected(self):
     stub_mod_check_output(self, cli)
     stub_base_which(self)
     self.check_output_answer = b'Nothing'
     with pretty_logging(stream=mocks.StringIO()) as err:
         results = cli._get_bin_version('some_app')
     self.assertIn(
         "encountered unexpected error while trying to find version of "
         "'some_app'", err.getvalue())
     self.assertIsNone(results)
예제 #30
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_helper_attr(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     with self.assertRaises(AttributeError) as e:
         driver.no_such_attr_here
     self.assertIn('no_such_attr_here', str(e.exception))
     self.assertIsNot(driver.mgr_init, None)
     self.assertIsNot(driver.get_mgr_version, None)
     self.assertTrue(driver.mgr_install(['calmjs']))
     self.assertEqual(self.call_args[0], (['mgr', 'install'],))
예제 #31
0
 def test_helper_attr(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     with self.assertRaises(AttributeError) as e:
         driver.no_such_attr_here
     self.assertIn('no_such_attr_here', str(e.exception))
     self.assertIsNot(driver.mgr_init, None)
     self.assertIsNot(driver.get_mgr_version, None)
     self.assertTrue(driver.mgr_install(['calmjs']))
     self.assertEqual(self.call_args[0], (['mgr', 'install'], ))
예제 #32
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_working_dir_set(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     some_cwd = self.cwd
     driver = cli.PackageManagerDriver(
         pkg_manager_bin='mgr', working_dir=some_cwd)
     with pretty_logging(stream=mocks.StringIO()):
         driver.pkg_manager_install(['calmjs'])
     args, kwargs = self.call_args
     self.assertNotIn('PATH', kwargs)
     self.assertEqual(kwargs['cwd'], some_cwd)
예제 #33
0
 def test_set_binary(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='bower')
     # this will call ``bower install`` instead.
     with pretty_logging(stream=mocks.StringIO()) as fd:
         driver.pkg_manager_install()
         self.assertIn(
             "no package name supplied, "
             "but continuing with 'bower install'", fd.getvalue())
     self.assertEqual(self.call_args, ((['bower', 'install'], ), {}))
예제 #34
0
 def test_working_dir_set(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     some_cwd = mkdtemp(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                       working_dir=some_cwd)
     with pretty_logging(stream=mocks.StringIO()):
         driver.pkg_manager_install()
     args, kwargs = self.call_args
     self.assertNotIn('PATH', kwargs)
     self.assertEqual(kwargs['cwd'], some_cwd)
예제 #35
0
    def test_stub_base_which(self):
        from calmjs import base
        utils.stub_base_which(self)
        _marker = object()
        self.assertIs(base.which(_marker), _marker)
        self.doCleanups()

        _alternative = object()
        utils.stub_base_which(self, _alternative)
        _marker = object()
        self.assertIs(base.which(_marker), _alternative)
        self.doCleanups()
예제 #36
0
    def test_stub_base_which(self):
        from calmjs import base
        utils.stub_base_which(self)
        _marker = object()
        self.assertIs(base.which(_marker), _marker)
        self.doCleanups()

        _alternative = object()
        utils.stub_base_which(self, _alternative)
        _marker = object()
        self.assertIs(base.which(_marker), _alternative)
        self.doCleanups()
예제 #37
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_predefined_path(self):
     # ensure that the various paths are passed to env or cwd.
     stub_mod_call(self, cli)
     stub_base_which(self)
     somepath = mkdtemp(self)
     cwd = self.cwd
     driver = cli.PackageManagerDriver(
         pkg_manager_bin='mgr', env_path=somepath, working_dir=cwd)
     with pretty_logging(stream=mocks.StringIO()):
         driver.pkg_manager_install(['calmjs'])
     args, kwargs = self.call_args
     self.assertEqual(kwargs['env']['PATH'].split(pathsep)[0], somepath)
     self.assertEqual(kwargs['cwd'], cwd)
예제 #38
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 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'}),
     }))
예제 #39
0
 def test_advices(self):
     stub_base_which(self)
     stub_mod_call(self, cli)
     build_dir = mkdtemp(self)
     advices = []
     driver = cli.KarmaDriver.create()
     spec = Spec(build_dir=build_dir)
     spec.advise(AFTER_TEST, advices.append, AFTER_TEST)
     spec.advise(BEFORE_TEST, advices.append, BEFORE_TEST)
     driver.test_spec(spec)
     # XXX should AFTER_TEST also run if test failed?
     # XXX what other advices should apply, i.e. failure/error/success
     self.assertEqual(advices, [BEFORE_TEST, AFTER_TEST])
예제 #40
0
파일: test_cli.py 프로젝트: calmjs/calmjs
    def test_alternative_install_cmd(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr', install_cmd='sync')
        driver.pkg_manager_install(['calmjs'])
        self.assertEqual(self.call_args[0], (['mgr', 'sync'],))

        # Naturally, the short hand call will be changed.
        # note that args is NOT the package_name, and thus this just
        # means that the installation may not operate as expected off
        # the package.
        driver.mgr_sync(['calmjs'], args=('all',))
        self.assertEqual(self.call_args[0], (['mgr', 'sync', 'all'],))
예제 #41
0
 def test_predefined_path(self):
     # ensure that the various paths are passed to env or cwd.
     stub_mod_call(self, cli)
     stub_base_which(self)
     somepath = mkdtemp(self)
     cwd = mkdtemp(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                       env_path=somepath,
                                       working_dir=cwd)
     with pretty_logging(stream=mocks.StringIO()):
         driver.pkg_manager_install()
     args, kwargs = self.call_args
     self.assertEqual(kwargs['env']['PATH'].split(pathsep)[0], somepath)
     self.assertEqual(kwargs['cwd'], cwd)
예제 #42
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'}),
                      }))
예제 #43
0
    def test_alternative_install_cmd(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                          install_cmd='sync')
        driver.pkg_manager_install(['calmjs'])
        self.assertEqual(self.call_args[0], (['mgr', 'sync'], ))

        # Naturally, the short hand call will be changed.
        # note that args is NOT the package_name, and thus this just
        # means that the installation may not operate as expected off
        # the package.
        driver.mgr_sync(['calmjs'], args=('all', ))
        self.assertEqual(self.call_args[0], (['mgr', 'sync', 'all'], ))
예제 #44
0
    def test_yarn_install_package_json(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_yarn)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # This is faked.
        with pretty_logging(stream=StringIO()) as stderr:
            yarn.yarn_install()
            self.assertIn(
                "no package name supplied, "
                "not continuing with 'yarn install'", stderr.getvalue())
        # However we make sure that it's been fake called
        self.assertIsNone(self.call_args)
        self.assertFalse(exists(join(tmpdir, 'package.json')))
예제 #45
0
    def test_npm_install_package_json(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_npm)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # This is faked.
        with pretty_logging(stream=StringIO()) as stderr:
            npm.npm_install()
            self.assertIn(
                "no package name supplied, "
                "but continuing with 'npm install'", stderr.getvalue())
        # However we make sure that it's been fake called
        self.assertEqual(self.call_args, (([which_npm, 'install'],), {}))
        self.assertFalse(exists(join(tmpdir, 'package.json')))
예제 #46
0
파일: test_yarn.py 프로젝트: calmjs/calmjs
    def test_yarn_install_package_json(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_yarn)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # This is faked.
        with pretty_logging(stream=StringIO()) as stderr:
            yarn.yarn_install()
            self.assertIn(
                "no package name supplied, "
                "not continuing with 'yarn install'", stderr.getvalue())
        # However we make sure that it's been fake called
        self.assertIsNone(self.call_args)
        self.assertFalse(exists(join(tmpdir, 'package.json')))
예제 #47
0
 def test_helper_attr(self):
     stub_mod_call(self, cli)
     stub_base_which(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     with self.assertRaises(AttributeError) as e:
         driver.no_such_attr_here
     self.assertIn('no_such_attr_here', str(e.exception))
     self.assertIsNot(driver.mgr_init, None)
     self.assertIsNot(driver.get_mgr_version, None)
     with pretty_logging(stream=mocks.StringIO()) as stderr:
         driver.mgr_install()
         self.assertIn(
             "no package name supplied, "
             "but continuing with 'mgr install'", stderr.getvalue())
     self.assertEqual(self.call_args, ((['mgr', 'install'], ), {}))
예제 #48
0
    def test_base(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        build_dir = mkdtemp(self)
        driver = cli.KarmaDriver.create()
        toolchain = NullToolchain()
        spec = Spec(build_dir=build_dir)
        driver.setup_toolchain_spec(toolchain, spec)
        driver.test_spec(spec)

        conf = join(build_dir, 'karma.conf.js')
        self.assertTrue(exists(conf))
        args = self.call_args[0][0]
        self.assertIn('karma', args[0])
        self.assertEqual('start', args[1])
        self.assertEqual(conf, args[2])
예제 #49
0
    def test_config_written_correctly(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        build_dir = mkdtemp(self)
        driver = cli.KarmaDriver.create()
        toolchain = NullToolchain()
        spec = Spec(build_dir=build_dir)
        driver.setup_toolchain_spec(toolchain, spec)
        driver.test_spec(spec)

        # verify that the resulting file is a function that expect a
        # function that accepts an object, that is the configuration.
        result = json.loads(node(
            'require("%s")({set: function(a) {\n'
            '    process.stdout.write(JSON.stringify(a));\n'
            '}});\n' % join(build_dir, 'karma.conf.js').replace('\\', '\\\\')
        )[0])
        self.assertTrue(isinstance(result, dict))
예제 #50
0
파일: test_cli.py 프로젝트: calmjs/calmjs
    def test_pkg_manager_cmd_production_flag_set(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        self.setup_requirements_json()
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr', pkgdef_filename='requirements.json',
            dep_keys=('require',), devkey='require',
        )

        with pretty_logging(stream=mocks.StringIO()) as log:
            driver.pkg_manager_install(['calmpy.pip'], production=True)
        self.assertNotIn('WARNING', log.getvalue())
        self.assertEqual(self.call_args[0], (
            ['mgr', 'install', '--production=true'],))

        with pretty_logging(stream=mocks.StringIO()) as log:
            driver.pkg_manager_install(['calmpy.pip'], production=False)
        self.assertNotIn('WARNING', log.getvalue())
        self.assertEqual(self.call_args[0], (
            ['mgr', 'install', '--production=false'],))
예제 #51
0
    def test_setup_class_install_environment_install(self):
        from calmjs import cli
        from calmjs.npm import Driver

        utils.stub_mod_call(self, cli)
        utils.stub_base_which(self, 'npm')
        utils.stub_os_environ(self)
        os.environ.pop('CALMJS_TEST_ENV', '')

        cwd = os.getcwd()
        TestCase = type('TestCase', (unittest.TestCase,), {})
        utils.setup_class_install_environment(
            TestCase, Driver, ['dummy_package'])
        self.assertEqual(self.mock_tempfile.count, 1)
        self.assertNotEqual(TestCase._env_root, cwd)
        self.assertEqual(TestCase._env_root, TestCase._cls_tmpdir)
        self.assertTrue(exists(join(TestCase._env_root, 'package.json')))
        p, kw = self.call_args
        self.assertEqual(p, (['npm', 'install'],))
        self.assertEqual(kw['cwd'], TestCase._cls_tmpdir)
예제 #52
0
파일: test_cli.py 프로젝트: calmjs/calmjs
    def test_pkg_manager_cmd_production_flag_unset(self):
        stub_check_interactive(self, False)
        stub_mod_call(self, cli)
        stub_base_which(self)
        self.setup_requirements_json()
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr', pkgdef_filename='requirements.json',
            dep_keys=('require',), devkey='require',
        )

        with pretty_logging(stream=mocks.StringIO()) as log:
            driver.pkg_manager_install(['calmpy.pip'])

        self.assertIn('WARNING', log.getvalue())
        self.assertIn(
            'undefined production flag may result in unexpected installation '
            'behavior', log.getvalue()
        )
        self.assertIn("non-interactive", log.getvalue())
        self.assertIn("'require' may be ignored", log.getvalue())
        self.assertEqual(self.call_args[0], (['mgr', 'install'],))
예제 #53
0
    def test_alternative_install_cmd(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                          install_cmd='sync')
        with pretty_logging(stream=mocks.StringIO()) as stderr:
            driver.pkg_manager_install()
            self.assertIn(
                "no package name supplied, "
                "but continuing with 'mgr sync'", stderr.getvalue())
        self.assertEqual(self.call_args, ((['mgr', 'sync'], ), {}))

        # Naturally, the short hand call will be changed.
        with pretty_logging(stream=mocks.StringIO()) as stderr:
            # note that args is NOT the package_name, and thus this just
            # means that init won't be called.
            driver.mgr_sync(args=('all', ))
            self.assertIn(
                "no package name supplied, "
                "but continuing with 'mgr sync'", stderr.getvalue())
        self.assertEqual(self.call_args, ((['mgr', 'sync', 'all'], ), {}))
예제 #54
0
    def test_pkg_manager_cmd_production_flag_set(self):
        stub_mod_call(self, cli)
        stub_base_which(self)
        self.setup_requirements_json()
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr',
            pkgdef_filename='requirements.json',
            dep_keys=('require', ),
            devkey='require',
        )

        with pretty_logging(stream=mocks.StringIO()) as log:
            driver.pkg_manager_install(['calmpy.pip'], production=True)
        self.assertNotIn('WARNING', log.getvalue())
        self.assertEqual(self.call_args[0],
                         (['mgr', 'install', '--production=true'], ))

        with pretty_logging(stream=mocks.StringIO()) as log:
            driver.pkg_manager_install(['calmpy.pip'], production=False)
        self.assertNotIn('WARNING', log.getvalue())
        self.assertEqual(self.call_args[0],
                         (['mgr', 'install', '--production=false'], ))
예제 #55
0
    def test_karma_runtime_arguments(self):
        stub_stdouts(self)
        stub_mod_call(self, cli)
        stub_base_which(self, 'karma')

        build_dir = mkdtemp(self)
        rt = KarmaRuntime(KarmaDriver())
        # the artifact in our case is identical to the source file
        artifact = resource_filename('calmjs.dev', 'main.js')
        result = rt([
            'run', '--artifact', artifact,
            '--build-dir', build_dir,
            '--test-with-package', 'calmjs.dev',
            '--extra-frameworks', 'my_framework',
            '--browser', 'Chromium,Firefox',
        ])
        self.assertEqual(result['artifact_paths'], [artifact])
        self.assertTrue(exists(result['karma_config_path']))
        self.assertIn('karma_config_path', result)
        self.assertIn('my_framework', result['karma_config']['frameworks'])
        self.assertEqual(
            ['Chromium', 'Firefox'], result['karma_config']['browsers'])
예제 #56
0
파일: test_yarn.py 프로젝트: calmjs/calmjs
    def test_install_view(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_yarn)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['yarn', '--install', '--view'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

        with open(os.path.join(tmpdir, 'package.json')) as fd:
            result = json.load(fd)

        self.assertEqual(result, {
            'dependencies': {'jquery': '~1.11.0'},
            'devDependencies': {},
            'name': 'foo',
        })
        self.assertEqual(self.call_args[0], ([which_yarn, 'install'],))
예제 #57
0
    def test_pkg_manager_cmd_production_flag_unset(self):
        stub_check_interactive(self, False)
        stub_mod_call(self, cli)
        stub_base_which(self)
        self.setup_requirements_json()
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr',
            pkgdef_filename='requirements.json',
            dep_keys=('require', ),
            devkey='require',
        )

        with pretty_logging(stream=mocks.StringIO()) as log:
            driver.pkg_manager_install(['calmpy.pip'])

        self.assertIn('WARNING', log.getvalue())
        self.assertIn(
            'undefined production flag may result in unexpected installation '
            'behavior', log.getvalue())
        self.assertIn("non-interactive", log.getvalue())
        self.assertIn("'require' may be ignored", log.getvalue())
        self.assertEqual(self.call_args[0], (['mgr', 'install'], ))
예제 #58
0
파일: test_npm.py 프로젝트: calmjs/calmjs
    def test_install_init_install_develop(self):
        stub_mod_call(self, cli)
        stub_base_which(self, which_npm)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['npm', '--init', '--install', '--development'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

        with open(os.path.join(tmpdir, 'package.json')) as fd:
            result = json.load(fd)

        self.assertEqual(result, {
            'dependencies': {'jquery': '~1.11.0'},
            'devDependencies': {},
            'name': 'foo',
        })
        # Should still invoke install
        self.assertEqual(self.call_args[0], (
            [which_npm, 'install', '--production=false'],))
예제 #59
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_node_version_mocked(self):
     stub_mod_check_output(self, cli)
     stub_base_which(self)
     self.check_output_answer = b'v0.10.25'
     version = cli.get_node_version()
     self.assertEqual(version, (0, 10, 25))
예제 #60
0
파일: test_cli.py 프로젝트: calmjs/calmjs
 def test_get_bin_version_short(self):
     stub_mod_check_output(self, cli)
     stub_base_which(self)
     self.check_output_answer = b'1'
     results = cli.get_bin_version('some_app')
     self.assertEqual(results, (1,))