Esempio n. 1
0
    def test_get_env(self):
        subprocess.check_output = MagicMock(return_value=None)
        java = Java(self.JAVA_HOME)

        env = java.get_env()

        self.assertEqual(java.java_home, env['JAVA_HOME'])
        self.assertTrue(os.environ['PATH'] in env['PATH'])
        self.assertTrue(os.path.join(java.java_home, 'bin') in env['PATH'])
Esempio n. 2
0
    def test_get_env_with_variables(self):
        subprocess.check_output = MagicMock(return_value=None)
        java = Java(self.JAVA_HOME)

        env = java.get_env({'A_B_C_D_583': 'OK'})

        self.assertEqual(java.java_home, env['JAVA_HOME'])
        self.assertTrue(os.environ['PATH'] in env['PATH'])
        self.assertTrue(os.path.join(java.java_home, 'bin') in env['PATH'])
        self.assertEqual('OK', env['A_B_C_D_583'])
Esempio n. 3
0
    def test_exec_file_not_found_error(self):
        subprocess.check_output = MagicMock(side_effect=FileNotFoundError())

        with self.assertRaises(FileNotFoundError):
            Java._exec('java', cwd=None, env=None, timeout=None)

        subprocess.check_output.assert_called_once_with(
            ['java'],
            cwd=None,
            env=None,
            timeout=None,
            stderr=subprocess.STDOUT)
Esempio n. 4
0
    def test_version_javac(self):
        subprocess.check_output = MagicMock(return_value=None)
        java = Java(self.JAVA_HOME)

        subprocess.check_output = MagicMock(return_value='javac 1.8.0_202')

        self.assertEqual('javac 1.8.0_202', java._version_javac())
        subprocess.check_output.assert_called_once_with(
            [java.javac, '-version'],
            cwd=None,
            env=java.get_env(),
            timeout=JAVA_TIMEOUT,
            stderr=subprocess.STDOUT)
Esempio n. 5
0
    def test_run_javac(self):
        subprocess.check_output = MagicMock(return_value=None)
        java = Java(self.JAVA_HOME)

        subprocess.check_output = MagicMock(return_value='OK')

        self.assertEqual('OK', java.run_javac('file.java', 'b', 'c'))
        subprocess.check_output.assert_called_once_with(
            [java.javac, 'file.java', 'b', 'c'],
            cwd=None,
            env=java.get_env(),
            timeout=JAVA_TIMEOUT,
            stderr=subprocess.STDOUT)
Esempio n. 6
0
    def test_exec_java(self):
        subprocess.check_output = MagicMock(return_value=None)
        java = Java(self.JAVA_HOME)

        subprocess.check_output = MagicMock(return_value='OK')

        self.assertEqual('OK', java.exec_java('a', None, 1, 'b', 'c'))
        subprocess.check_output.assert_called_once_with(
            [os.path.join(self.JAVA_HOME, 'jre', 'bin', 'java'), 'b', 'c'],
            cwd='a',
            env=None,
            timeout=1,
            stderr=subprocess.STDOUT)
Esempio n. 7
0
    def test_exec_timeout_expired(self):
        subprocess.check_output = MagicMock(
            side_effect=subprocess.TimeoutExpired('', 0))

        with self.assertRaises(subprocess.TimeoutExpired):
            Java._exec('java', cwd=None, env=None, timeout=None)

        subprocess.check_output.assert_called_once_with(
            ['java'],
            cwd=None,
            env=None,
            timeout=None,
            stderr=subprocess.STDOUT)
Esempio n. 8
0
    def test_exec_process_error(self):
        subprocess.check_output = MagicMock(
            side_effect=subprocess.CalledProcessError(-1, ''))

        with self.assertRaises(subprocess.CalledProcessError):
            Java._exec('java', cwd=None, env=None, timeout=None)

        subprocess.check_output.assert_called_once_with(
            ['java'],
            cwd=None,
            env=None,
            timeout=None,
            stderr=subprocess.STDOUT)
Esempio n. 9
0
    def test_set_home_in_env(self):
        subprocess.check_output = MagicMock(return_value=None)
        os.environ['JAVA_HOME'] = self.JAVA_HOME

        java = Java()

        self.assertTrue(java.java.startswith(self.JAVA_HOME))
        self.assertTrue(java.javac.startswith(self.JAVA_HOME))

        subprocess.check_output.assert_any_call([java.java, '-version'],
                                                cwd=None,
                                                env=java.get_env(),
                                                timeout=JAVA_TIMEOUT,
                                                stderr=subprocess.STDOUT)

        subprocess.check_output.assert_any_call([java.javac, '-version'],
                                                cwd=None,
                                                env=java.get_env(),
                                                timeout=JAVA_TIMEOUT,
                                                stderr=subprocess.STDOUT)
Esempio n. 10
0
    def test_check_java_home_arg(self):
        subprocess.check_output = MagicMock(return_value=None)
        self._del_java_home_env()

        java = Java(self.JAVA_HOME)

        self.assertTrue(java.java.startswith(self.JAVA_HOME))
        self.assertTrue(java.javac.startswith(self.JAVA_HOME))

        subprocess.check_output.assert_any_call([java.java, '-version'],
                                                cwd=None,
                                                env=java.get_env(),
                                                timeout=JAVA_TIMEOUT,
                                                stderr=subprocess.STDOUT)

        subprocess.check_output.assert_any_call([java.javac, '-version'],
                                                cwd=None,
                                                env=java.get_env(),
                                                timeout=JAVA_TIMEOUT,
                                                stderr=subprocess.STDOUT)
Esempio n. 11
0
    def test_javac_property(self):
        subprocess.check_output = MagicMock(return_value=None)
        java = Java(self.JAVA_HOME)

        self.assertEqual(os.path.join(self.JAVA_HOME, 'bin', 'javac'),
                         java.javac)
Esempio n. 12
0
    def test_check_wrong_java_home(self):
        subprocess.check_output = MagicMock(side_effect=FileNotFoundError())

        with self.assertRaises(SystemExit):
            Java('wrong_java_home')
Esempio n. 13
0
    def test_check_java_home_none(self):
        self._del_java_home_env()

        with self.assertRaises(SystemExit):
            Java()
Esempio n. 14
0
    def test_java_property(self):
        java = Java(self.JAVA_HOME)
        java._check = MagicMock()

        self.assertEqual(os.path.join(self.JAVA_HOME, 'jre', 'bin', 'java'),
                         java.java)