Beispiel #1
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)
Beispiel #2
0
 def test_x11(self):
     stub_os_environ(self)
     os.environ.clear()
     os.environ['DISPLAY'] = ':0'
     self.assertEqual(utils.extract_gui_environ_keys(), {
         'DISPLAY': ':0',
     })
Beispiel #3
0
 def test_win32(self):
     stub_os_environ(self)
     os.environ.clear()
     os.environ['PROGRAMFILES'] = 'C:\\Program Files'
     self.assertEqual(utils.extract_gui_environ_keys(), {
         'PROGRAMFILES': 'C:\\Program Files',
     })
Beispiel #4
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 #5
0
 def test_set_env_path_with_node_path_with_environ(self):
     stub_os_environ(self)
     tmpdir, bin_dir, mgr_bin = 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)
Beispiel #6
0
 def test_stub_os_environ(self):
     self.assertNotEqual(os.environ['PATH'], '')
     original = os.environ['PATH']
     utils.stub_os_environ(self)
     os.environ['PATH'] = ''
     self.assertNotEqual(os.environ['PATH'], original)
     self.doCleanups()
     self.assertEqual(os.environ['PATH'], original)
Beispiel #7
0
 def test_stub_os_environ(self):
     self.assertNotEqual(os.environ['PATH'], '')
     original = os.environ['PATH']
     utils.stub_os_environ(self)
     os.environ['PATH'] = ''
     self.assertNotEqual(os.environ['PATH'], original)
     self.doCleanups()
     self.assertEqual(os.environ['PATH'], original)
Beispiel #8
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)
     self.assertIsNone(driver.which_with_node_modules())
Beispiel #9
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)
Beispiel #10
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()
Beispiel #11
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()
Beispiel #12
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())
Beispiel #13
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())
Beispiel #14
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))
Beispiel #15
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))
Beispiel #16
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 #17
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 #18
0
    def test_prepare_failure_which_fail(self):
        utils.stub_os_environ(self)
        utils.remember_cwd(self)

        # must go to a directory where r.js is guaranteed to not be
        # available through node_modules or the environmental PATH
        os.environ['NODE_PATH'] = ''
        os.environ['PATH'] = ''
        tmpdir = utils.mkdtemp(self)
        os.chdir(tmpdir)

        rjs = toolchain.RJSToolchain()
        spec = Spec()
        with self.assertRaises(RuntimeError) as e:
            rjs.prepare(spec)

        self.assertEqual(str(e.exception),
                         "unable to locate '%s'" % (rjs.rjs_bin))
Beispiel #19
0
    def test_prepare_failure_which_fail(self):
        utils.stub_os_environ(self)
        utils.remember_cwd(self)

        # must go to a directory where r.js is guaranteed to not be
        # available through node_modules or the environmental PATH
        os.environ['NODE_PATH'] = ''
        os.environ['PATH'] = ''
        tmpdir = utils.mkdtemp(self)
        os.chdir(tmpdir)

        rjs = toolchain.RJSToolchain()
        spec = Spec()
        with self.assertRaises(RuntimeError) as e:
            rjs.prepare(spec)

        self.assertEqual(str(e.exception), "unable to locate '%s'" % (
            rjs.rjs_bin
        ))
    def test_prepare_failure_which_fail(self):
        utils.stub_os_environ(self)
        utils.remember_cwd(self)

        # must go to a directory where webpack is guaranteed to not be
        # available through node_modules or the environmental PATH
        os.environ['NODE_PATH'] = ''
        os.environ['PATH'] = ''
        tmpdir = utils.mkdtemp(self)
        os.chdir(tmpdir)

        webpack = toolchain.WebpackToolchain()
        spec = Spec()
        with self.assertRaises(RuntimeError) as e:
            webpack.prepare(spec)

        # not fixed string because platform specific value.
        self.assertEqual(str(e.exception),
                         "unable to locate '%s'" % (webpack.webpack_bin))
Beispiel #21
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 #22
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 #23
0
    def test_create_for_module_vars_warning(self):
        stub_os_environ(self)
        tmpdir = mkdtemp(self)
        values = {}

        class MgrDriver(cli.PackageManagerDriver):
            def __init__(self, *a, **kw):
                kw['pkg_manager_bin'] = 'mgr'
                kw['working_dir'] = tmpdir
                super(MgrDriver, self).__init__(*a, **kw)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            with pretty_logging(stream=mocks.StringIO()) as err:
                driver = MgrDriver.create_for_module_vars(values)
            self.assertIn("Unable to locate the 'mgr' binary;", err.getvalue())

            self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
            self.assertIn("Unable to locate the 'mgr' binary;",
                          str(w[-1].message))

        self.assertTrue(isinstance(driver, MgrDriver))
Beispiel #24
0
    def test_create_for_module_vars_and_warning(self):
        stub_os_environ(self)
        tmpdir = mkdtemp(self)
        values = {}

        class MgrDriver(cli.PackageManagerDriver):
            def __init__(self, *a, **kw):
                kw['pkg_manager_bin'] = 'mgr'
                kw['working_dir'] = tmpdir
                super(MgrDriver, self).__init__(*a, **kw)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            driver = MgrDriver.create_for_module_vars(values)
            self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
            self.assertIn("Unable to locate the 'mgr' binary or runtime",
                          str(w[-1].message))

        self.assertTrue(isinstance(driver, MgrDriver))
        # Normally, these will be global names.
        self.assertIn('mgr_install', values)
        self.assertIn('mgr_init', values)
        self.assertIn('get_mgr_version', values)
Beispiel #25
0
    def test_create_for_module_vars_and_warning(self):
        stub_os_environ(self)
        tmpdir = mkdtemp(self)
        values = {}

        class MgrDriver(cli.PackageManagerDriver):
            def __init__(self, *a, **kw):
                kw['pkg_manager_bin'] = 'mgr'
                kw['working_dir'] = tmpdir
                super(MgrDriver, self).__init__(*a, **kw)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            driver = MgrDriver.create_for_module_vars(values)
            self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
            self.assertIn(
                "Unable to locate the 'mgr' binary or runtime",
                str(w[-1].message))

        self.assertTrue(isinstance(driver, MgrDriver))
        # Normally, these will be global names.
        self.assertIn('mgr_install', values)
        self.assertIn('mgr_init', values)
        self.assertIn('get_mgr_version', values)
Beispiel #26
0
 def setUp(self):
     remember_cwd(self)
     stub_os_environ(self)
     # Forcibly enable interactive mode.
     self.inst_interactive, npm.npm.cli_driver.interactive = (
         npm.npm.cli_driver.interactive, True)
Beispiel #27
0
 def test_node_no_path(self):
     stub_os_environ(self)
     os.environ['PATH'] = ''
     with pretty_logging(stream=mocks.StringIO()) as err:
         self.assertIsNone(cli.get_node_version())
     self.assertIn("failed to execute 'node'", err.getvalue())
Beispiel #28
0
 def test_node_run_no_path(self):
     stub_os_environ(self)
     os.environ['PATH'] = ''
     with self.assertRaises(OSError):
         cli.node('process.stdout.write("Hello World!");')
Beispiel #29
0
 def test_node_run_no_path(self):
     stub_os_environ(self)
     os.environ['PATH'] = ''
     with self.assertRaises(OSError):
         cli.node('process.stdout.write("Hello World!");')
Beispiel #30
0
 def test_node_no_path(self):
     stub_os_environ(self)
     os.environ['PATH'] = ''
     with pretty_logging(stream=mocks.StringIO()) as err:
         self.assertIsNone(cli.get_node_version())
     self.assertIn("failed to execute 'node'", err.getvalue())
Beispiel #31
0
 def setUp(self):
     self._platform = sys.platform
     stub_os_environ(self)
Beispiel #32
0
 def setUp(self):
     remember_cwd(self)
     stub_os_environ(self)
     stub_check_interactive(self, True)
Beispiel #33
0
 def setUp(self):
     remember_cwd(self)
     stub_os_environ(self)
     stub_check_interactive(self, True)
Beispiel #34
0
 def test_base(self):
     stub_os_environ(self)
     os.environ.clear()
     self.assertEqual(utils.extract_gui_environ_keys(), {})
Beispiel #35
0
 def setUp(self):
     self._platform = sys.platform
     stub_os_environ(self)