예제 #1
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': '.'
            }),
        }))
예제 #2
0
    def test_pkg_manager_init(self):
        # we still need a temporary directory, but the difference is
        # that whether the instance contains it or not.
        self.setup_requirements_json()
        remember_cwd(self)
        cwd = mkdtemp(self)
        os.chdir(cwd)

        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr',
            pkgdef_filename='requirements.json',
            dep_keys=('require', ),
        )
        driver.pkg_manager_init('calmpy.pip', interactive=False)

        target = join(cwd, 'requirements.json')
        self.assertTrue(exists(target))
        with open(target) as fd:
            result = json.load(fd)
        self.assertEqual(result, {
            "require": {
                "setuptools": "25.1.6"
            },
            "name": "calmpy.pip",
        })
예제 #3
0
 def test_set_env_path_with_node_modules_fail(self):
     stub_os_environ(self)
     tmpdir = mkdtemp(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                       working_dir=tmpdir)
     self.assertFalse(driver._set_env_path_with_node_modules())
     self.assertIsNone(driver.env_path)
예제 #4
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'], ))
예제 #5
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))
예제 #6
0
    def test_pkg_manager_init_working_dir(self):
        self.setup_requirements_json()
        remember_cwd(self)
        original = mkdtemp(self)
        os.chdir(original)
        cwd = mkdtemp(self)
        target = join(cwd, 'requirements.json')

        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr',
            pkgdef_filename='requirements.json',
            dep_keys=('require', ),
            working_dir=cwd,
        )
        driver.pkg_manager_init('calmpy.pip', interactive=False)

        self.assertFalse(exists(join(original, 'requirements.json')))
        self.assertTrue(exists(target))

        with open(target) as fd:
            result = json.load(fd)
        self.assertEqual(result, {
            "require": {
                "setuptools": "25.1.6"
            },
            "name": "calmpy.pip",
        })
예제 #7
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',
                                    interactive=False,
                                    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"}})

        driver.pkg_manager_init('calmpy.pip',
                                interactive=False,
                                overwrite=True)
        with open(target) as fd:
            result = json.load(fd)
        self.assertEqual(result, {
            "require": {
                "setuptools": "25.1.6"
            },
            "name": "calmpy.pip",
        })
예제 #8
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',
                                interactive=False,
                                merge=True,
                                overwrite=True)
        self.assertNotEqual(
            result, {
                "require": {
                    "calmpy": "1.0.0",
                    "setuptools": "25.1.6",
                },
                "name": "calmpy.pip",
            })
예제 #9
0
 def test_pkg_manager_view_extras_requires(self):
     working_set = self.setup_requirements_json()
     working_set.add(
         pkg_resources.Distribution(
             metadata=MockProvider({
                 'requires.txt': '[dev]\ncalmpy.pip',
             }),
             project_name='site',
             version='0.0.0',
         ))
     driver = cli.PackageManagerDriver(
         pkg_manager_bin='mgr',
         pkgdef_filename='requirements.json',
         dep_keys=('require', ),
     )
     result = driver.pkg_manager_view('site')
     self.assertEqual(result, {
         "require": {},
         "name": "site",
     })
     result = driver.pkg_manager_view('site[dev]')
     self.assertEqual(result, {
         "require": {
             "setuptools": "25.1.6"
         },
         "name": "site[dev]",
     })
예제 #10
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'], ), {}))
예제 #11
0
 def test_command_creation(self):
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     cmd = runtime.PackageManagerRuntime(driver)
     text = cmd.argparser.format_help()
     self.assertIn(
         "run 'mgr install' with generated 'default.json';",
         text,
     )
예제 #12
0
 def test_set_env_path_with_node_path_with_environ(self):
     stub_os_environ(self)
     tmpdir, bin_dir = self.fake_mgr_bin()
     # define a NODE_PATH set to a valid node_modules
     os.environ['NODE_PATH'] = join(tmpdir, 'node_modules')
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     self.assertTrue(driver._set_env_path_with_node_modules())
     self.assertEqual(driver.env_path, bin_dir)
예제 #13
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)
예제 #14
0
 def test_driver_run_failure(self):
     # testing for success may actually end up being extremely
     # annoying, so we are going to avoid that and let the integrated
     # subclasses deal with it.
     stub_os_environ(self)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     os.environ['PATH'] = ''
     with self.assertRaises(OSError):
         driver.run()
예제 #15
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)
예제 #16
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)
예제 #17
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'}),
                      }))
예제 #18
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)
예제 #19
0
    def test_which_is_set(self):
        stub_os_environ(self)
        tmpdir = mkdtemp(self)
        mgr_bin = self.create_fake_mgr_bin(tmpdir)
        driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
        driver.env_path = tmpdir
        self.assertEqual(normcase(driver.which()), normcase(mgr_bin))

        driver.env_path = None
        self.assertIsNone(driver.which())
예제 #20
0
 def test_pkg_manager_cmd_production_flag_warnings_noninteractive(self):
     stub_check_interactive(self, False)
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr', devkey='blah')
     with pretty_logging(stream=mocks.StringIO()) as log:
         self.assertEqual(driver._prodev_flag(None, None, True), [])
     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("'blah' may be ignored", log.getvalue())
예제 #21
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'], ))
예제 #22
0
 def test_set_env_path_with_node_modules_success(self):
     tmpdir, bin_dir = self.fake_mgr_bin()
     # constructor with an explicit working directory.
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr',
                                       working_dir=tmpdir)
     self.assertIsNone(driver.env_path)
     self.assertTrue(driver._set_env_path_with_node_modules())
     self.assertEqual(driver.env_path, bin_dir)
     # should still result in the same thing.
     self.assertTrue(driver._set_env_path_with_node_modules())
     self.assertEqual(driver.env_path, bin_dir)
예제 #23
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)
예제 #24
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'], ), {}))
예제 #25
0
 def test_set_env_path_with_node_path_success(self):
     tmpdir, bin_dir = self.fake_mgr_bin()
     # default constructor
     driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
     self.assertIsNone(driver.env_path)
     # using NODE_PATH set to a valid node_modules
     driver.node_path = join(tmpdir, 'node_modules')
     self.assertTrue(driver._set_env_path_with_node_modules())
     self.assertEqual(driver.env_path, bin_dir)
     # should still result in the same thing.
     self.assertTrue(driver._set_env_path_with_node_modules())
     self.assertEqual(driver.env_path, bin_dir)
예제 #26
0
    def test_which_is_set_env_path(self):
        stub_os_environ(self)
        tmpdir = mkdtemp(self)
        mgr_bin = self.create_fake_mgr_bin(tmpdir)
        driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
        # With both env_path attr and environ PATH set
        os.environ['PATH'] = driver.env_path = tmpdir
        self.assertEqual(normcase(driver.which()), normcase(mgr_bin))

        # the autodetection should still work through ENV_PATH
        driver.env_path = None
        self.assertEqual(normcase(driver.which()), normcase(mgr_bin))
예제 #27
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'], ))
예제 #28
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'}),
                      }))
예제 #29
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)
예제 #30
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'], ), {}))