Beispiel #1
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'], ))
Beispiel #2
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))
Beispiel #3
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'], ))
Beispiel #4
0
    def test_install_no_init_has_package_json_interactive_default_input(self):
        stub_stdin(self, u'')
        stub_mod_call(self, cli)
        tmpdir = mkdtemp(self)

        with open(os.path.join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({
                'dependencies': {'jquery': '~3.0.0'},
                'devDependencies': {}
            }, fd)

        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['yarn', '--install', '--interactive'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

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

        # Existing package.json will not be overwritten.
        self.assertEqual(result, {
            'dependencies': {'jquery': '~3.0.0'},
            'devDependencies': {},
        })
        # Ensure that install is NOT called.
        self.assertIsNone(self.call_args)
Beispiel #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'], ))
Beispiel #6
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'],))
Beispiel #7
0
    def test_install_no_init_has_package_json_interactive_default_input(self):
        stub_stdin(self, u'')
        stub_mod_call(self, cli)
        tmpdir = mkdtemp(self)

        with open(os.path.join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({
                'dependencies': {'jquery': '~3.0.0'},
                'devDependencies': {}
            }, fd)

        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['npm', '--install', '--interactive'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

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

        # Existing package.json will not be overwritten.
        self.assertEqual(result, {
            'dependencies': {'jquery': '~3.0.0'},
            'devDependencies': {},
        })
        # Ensure that install is NOT called.
        self.assertIsNone(self.call_args)
Beispiel #8
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 #9
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 #10
0
    def setUp(self):
        # save working directory
        remember_cwd(self)

        # All the pre-made setup.
        stub_mod_call(self, cli)
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')
        underscore = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'underscore': '~1.8.0'},
            })),
        ), 'underscore', '1.8.0')
        named = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~3.0.0'},
                'name': 'named-js',
            })),
        ), 'named', '2.0.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        working_set.add(underscore, self._calmjs_testing_tmpdir)
        working_set.add(named, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        stub_mod_check_interactive(self, [cli], True)
        # also save this
        self.inst_interactive = npm.npm.cli_driver.interactive
Beispiel #11
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'], ))
Beispiel #12
0
    def test_setup_class_install_environment_predefined_no_dir(self):
        from calmjs.cli import PackageManagerDriver
        from calmjs import cli

        utils.stub_os_environ(self)
        utils.stub_mod_call(self, cli)
        cwd = mkdtemp(self)
        # we have the mock_tempfile context...
        self.assertEqual(self.mock_tempfile.count, 1)
        os.chdir(cwd)

        # a very common use case
        os.environ['CALMJS_TEST_ENV'] = '.'
        TestCase = type('TestCase', (unittest.TestCase,), {})
        # the directory not there.
        with self.assertRaises(unittest.SkipTest):
            utils.setup_class_install_environment(
                TestCase, PackageManagerDriver, [])
        # temporary directory should not be created as the skip will
        # also stop the teardown from running
        self.assertEqual(self.mock_tempfile.count, 1)
        # this is still set, but irrelevant.
        self.assertEqual(TestCase._env_root, cwd)
        # tmpdir not set.
        self.assertFalse(hasattr(TestCase, '_cls_tmpdir'))
Beispiel #13
0
    def test_pkg_manager_init_exists_and_overwrite(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": {}}, fd)

        with pretty_logging(stream=mocks.StringIO()) as err:
            driver.pkg_manager_init('calmpy.pip', overwrite=False)

        self.assertIn('not overwriting existing ', err.getvalue())
        self.assertIn('requirements.json', err.getvalue())
        with open(target) as fd:
            result = json.load(fd)
        self.assertNotEqual(result, {"require": {"setuptools": "25.1.6"}})

        stub_mod_call(self, cli)
        with pretty_logging(stream=mocks.StringIO()) as err:
            # ensure the return value is False
            self.assertFalse(
                driver.pkg_manager_install('calmpy.pip', overwrite=False))

        driver.pkg_manager_init('calmpy.pip', overwrite=True)
        with open(target) as fd:
            result = json.load(fd)
        self.assertEqual(result, {
            "require": {"setuptools": "25.1.6"},
            "name": "calmpy.pip",
        })
Beispiel #14
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'], ), {}))
Beispiel #15
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))
Beispiel #16
0
    def setUp(self):
        # save working directory
        remember_cwd(self)

        # All the pre-made setup.
        stub_mod_call(self, cli)
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')
        underscore = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'underscore': '~1.8.0'},
            })),
        ), 'underscore', '1.8.0')
        named = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~3.0.0'},
                'name': 'named-js',
            })),
        ), 'named', '2.0.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        working_set.add(underscore, self._calmjs_testing_tmpdir)
        working_set.add(named, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)
        stub_check_interactive(self, True)
Beispiel #17
0
    def test_npm_binary_not_found_debugger(self):
        from calmjs import utils

        def fake_post_mortem(*a, **kw):
            sys.stdout.write('(Pdb) ')

        remember_cwd(self)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        rt = self.setup_runtime()
        # stub_stdin(self, u'quit\n')
        stub_stdouts(self)

        # ensure the binary is not found.
        stub_mod_call(self, cli, fake_error(IOError))
        stub_item_attr_value(self, utils, 'post_mortem', fake_post_mortem)
        rt(['-dd', 'foo', '--install', 'example.package2'])

        self.assertIn("ERROR", sys.stderr.getvalue())
        self.assertIn("invocation of the 'npm' binary failed;",
                      sys.stderr.getvalue())
        self.assertIn("terminating due to exception", sys.stderr.getvalue())
        self.assertIn("Traceback ", sys.stderr.getvalue())
        self.assertIn("(Pdb)", sys.stdout.getvalue())

        stub_stdouts(self)
        self.assertNotIn("(Pdb)", sys.stdout.getvalue())
        rt(['foo', '--install', 'example.package2', '--debugger'])
        self.assertIn("(Pdb)", sys.stdout.getvalue())
Beispiel #18
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'],))
Beispiel #19
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 #20
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'], ), {}))
Beispiel #21
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(['calmjs'], args=('--pedantic',))
     self.assertEqual(
         self.call_args[0], (['mgr', 'install', '--pedantic'],))
Beispiel #22
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(['calmjs'])
     val = stderr.getvalue()
     self.assertIn("invocation of the 'mgr' binary failed", val)
Beispiel #23
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)
Beispiel #24
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)
Beispiel #25
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(['calmjs'])
     args, kwargs = self.call_args
     self.assertNotIn('PATH', kwargs)
     self.assertNotIn('cwd', kwargs)
Beispiel #26
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)
Beispiel #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)
Beispiel #28
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 #29
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(['calmjs'])
     args, kwargs = self.call_args
     self.assertNotEqual(kwargs['env']['PATH'].split(pathsep)[0], bad_path)
Beispiel #30
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)
Beispiel #31
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'], ), {}))
Beispiel #32
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)
Beispiel #33
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'],))
Beispiel #34
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'], ))
Beispiel #35
0
 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)
Beispiel #36
0
    def test_npm_interrupted(self):
        remember_cwd(self)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        rt = self.setup_runtime()

        stub_stdouts(self)
        # ensure the binary is not found.
        stub_mod_call(self, cli, fake_error(KeyboardInterrupt))
        rt(['foo', '--install', 'example.package2'])
        self.assertIn("CRITICAL", sys.stderr.getvalue())
        self.assertIn("termination requested; aborted.", sys.stderr.getvalue())
Beispiel #37
0
    def test_critical_log_exception(self):
        remember_cwd(self)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        rt = self.setup_runtime()

        stub_stdouts(self)
        # ensure the binary is not found.
        stub_mod_call(self, cli, fake_error(RuntimeError('fake error')))
        rt(['foo', '--install', 'example.package2'])
        self.assertIn("CRITICAL calmjs.runtime RuntimeError: fake error",
                      sys.stderr.getvalue())
Beispiel #38
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 = 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)
Beispiel #39
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 #40
0
    def test_npm_binary_not_found(self):
        remember_cwd(self)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        rt = self.setup_runtime()

        stub_stdouts(self)
        # ensure the binary is not found.
        stub_mod_call(self, cli, fake_error(IOError))
        rt(['foo', '--install', 'example.package2'])
        self.assertIn("ERROR", sys.stderr.getvalue())
        self.assertIn("invocation of the 'npm' binary failed;",
                      sys.stderr.getvalue())
Beispiel #41
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])
Beispiel #42
0
    def test_yarn_install_package_json_no_overwrite_interactive(self):
        """
        Most of these package_json testing will be done in the next test
        class specific for ``yarn init``.
        """

        # Testing the implied init call
        stub_mod_call(self, cli)
        stub_stdouts(self)
        stub_stdin(self, 'n\n')
        stub_check_interactive(self, True)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # All the pre-made setup.
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json',
             json.dumps({
                 'dependencies': {
                     'jquery': '~1.11.0'
                 },
             })),
        ), 'foo', '1.9.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)

        # We are going to have a fake package.json
        with open(join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({}, fd)

        # capture the logging explicitly as the conditions which
        # determines how the errors are outputted differs from different
        # test harnesses.  Verify that later.
        with pretty_logging(stream=StringIO()) as stderr:
            # This is faked.
            yarn.yarn_install('foo', callback=prompt_overwrite_json)

        self.assertIn(
            "Overwrite '%s'? (Yes/No) [No] " % join(tmpdir, 'package.json'),
            sys.stdout.getvalue())
        # Ensure the error message.  Normally this is printed through
        # stderr via distutils custom logger and our handler bridge for
        # that which is tested elsewhere.
        self.assertIn("not continuing with 'yarn install'", stderr.getvalue())

        with open(join(tmpdir, 'package.json')) as fd:
            result = fd.read()
        # This should remain unchanged as no to overwrite is default.
        self.assertEqual(result, '{}')
Beispiel #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'], ))
Beispiel #44
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 #45
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'],))
Beispiel #46
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)
Beispiel #47
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')))
Beispiel #48
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'], ), {}))
Beispiel #49
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')))
Beispiel #50
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')))
Beispiel #51
0
    def test_yarn_install_package_json_no_overwrite_interactive(self):
        """
        Most of these package_json testing will be done in the next test
        class specific for ``yarn init``.
        """

        # Testing the implied init call
        stub_mod_call(self, cli)
        stub_stdouts(self)
        stub_stdin(self, 'n\n')
        stub_check_interactive(self, True)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)

        # All the pre-made setup.
        app = make_dummy_dist(self, (
            ('requires.txt', '\n'.join([])),
            ('package.json', json.dumps({
                'dependencies': {'jquery': '~1.11.0'},
            })),
        ), 'foo', '1.9.0')
        working_set = WorkingSet()
        working_set.add(app, self._calmjs_testing_tmpdir)
        stub_item_attr_value(self, dist, 'default_working_set', working_set)

        # We are going to have a fake package.json
        with open(join(tmpdir, 'package.json'), 'w') as fd:
            json.dump({}, fd)

        # capture the logging explicitly as the conditions which
        # determines how the errors are outputted differs from different
        # test harnesses.  Verify that later.
        with pretty_logging(stream=StringIO()) as stderr:
            # This is faked.
            yarn.yarn_install('foo', callback=prompt_overwrite_json)

        self.assertIn(
            "Overwrite '%s'? (Yes/No) [No] " % join(tmpdir, 'package.json'),
            sys.stdout.getvalue())
        # Ensure the error message.  Normally this is printed through
        # stderr via distutils custom logger and our handler bridge for
        # that which is tested elsewhere.
        self.assertIn("not continuing with 'yarn install'", stderr.getvalue())

        with open(join(tmpdir, 'package.json')) as fd:
            result = fd.read()
        # This should remain unchanged as no to overwrite is default.
        self.assertEqual(result, '{}')
Beispiel #52
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])
Beispiel #53
0
    def test_view(self):
        stub_mod_call(self, cli)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['yarn', '--view'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

        self.assertFalse(exists(join(tmpdir, 'package.json')))
        # also log handlers removed.
        self.assertEqual(len(getLogger('calmjs.cli').handlers), 0)
        # written to stdout with the correct indentation level.
        self.assertIn('\n        "jquery": "~1.11.0"', sys.stdout.getvalue())
Beispiel #54
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))
Beispiel #55
0
    def test_install_dryrun(self):
        stub_mod_call(self, cli)
        tmpdir = mkdtemp(self)
        os.chdir(tmpdir)
        dist = Distribution(dict(
            script_name='setup.py',
            script_args=['yarn', '--install', '--dry-run'],
            name='foo',
        ))
        dist.parse_command_line()
        dist.run_commands()

        self.assertFalse(exists(join(tmpdir, 'package.json')))
        # Ensure that install is NOT called.
        self.assertIsNone(self.call_args)
        # also log handlers removed.
        self.assertEqual(len(getLogger('calmjs.cli').handlers), 0)
        # However, default action is view, the package.json should be
        # written to stdout with the correct indentation level.
        self.assertIn('\n        "jquery": "~1.11.0"', sys.stdout.getvalue())
Beispiel #56
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)
Beispiel #57
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'],))
Beispiel #58
0
    def test_setup_class_install_environment_predefined_success(self):
        from calmjs.cli import PackageManagerDriver
        from calmjs import cli

        utils.stub_os_environ(self)
        utils.stub_mod_call(self, cli)
        cwd = mkdtemp(self)
        # we have the mock_tempfile context...
        self.assertEqual(self.mock_tempfile.count, 1)
        os.chdir(cwd)

        os.environ['CALMJS_TEST_ENV'] = '.'
        TestCase = type('TestCase', (unittest.TestCase,), {})
        # the directory now provided..
        os.mkdir(join(cwd, 'node_modules'))
        utils.setup_class_install_environment(
            TestCase, PackageManagerDriver, [])
        # temporary directory created nonetheless
        self.assertEqual(self.mock_tempfile.count, 2)
        self.assertEqual(TestCase._env_root, cwd)
        self.assertNotEqual(TestCase._env_root, TestCase._cls_tmpdir)
Beispiel #59
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'],))
Beispiel #60
0
    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'],))