Пример #1
0
    def test_check_output_helpererror(self):
        """HelperError if executable fails and require_success is set."""
        with self.assertRaises(HelperError) as cm:
            Helper._check_output(["false"])
        self.assertEqual(cm.exception.errno, 1)

        Helper._check_output(["false"], require_success=False)
Пример #2
0
 def test_download_and_expand(self):
     """Validate the download_and_expand() context_manager."""
     # Remove our stub for this test only
     Helper.download_and_expand = self._download_and_expand
     try:
         with Helper.download_and_expand("https://github.com/glennmatthews/cot/archive/master.tar.gz") as directory:
             self.assertTrue(os.path.exists(directory))
             self.assertTrue(os.path.exists(os.path.join(directory, "cot-master")))
             self.assertTrue(os.path.exists(os.path.join(directory, "cot-master", "COT")))
             self.assertTrue(os.path.exists(os.path.join(directory, "cot-master", "COT", "tests")))
             self.assertTrue(os.path.exists(os.path.join(directory, "cot-master", "COT", "tests", "ut.py")))
     except ConnectionError:
         # unable to connect to github - might be an isolated environment
         self.fail("ConnectionError when trying to download from GitHub")
     # Temporary directory should be cleaned up when done
     self.assertFalse(os.path.exists(directory))
Пример #3
0
 def setUp(self):
     """Test case setup function called automatically prior to each test."""
     self.helper = Helper("generic")
     super(HelperGenericTest, self).setUp()
Пример #4
0
class HelperGenericTest(HelperUT):

    """Test cases for generic Helper class."""

    def setUp(self):
        """Test case setup function called automatically prior to each test."""
        self.helper = Helper("generic")
        super(HelperGenericTest, self).setUp()

    def test_check_call_helpernotfounderror(self):
        """HelperNotFoundError if executable doesn't exist."""
        Helper._check_call = self._check_call
        self.assertRaises(HelperNotFoundError, Helper._check_call, ["not_a_command"])
        self.assertRaises(HelperNotFoundError, Helper._check_call, ["not_a_command"], require_success=True)

    def test_check_call_helpererror(self):
        """HelperError if executable fails and require_success is set."""
        Helper._check_call = self._check_call
        with self.assertRaises(HelperError) as cm:
            Helper._check_call(["false"])
        self.assertEqual(cm.exception.errno, 1)

        Helper._check_call(["false"], require_success=False)

    def test_check_output_helpernotfounderror(self):
        """HelperNotFoundError if executable doesn't exist."""
        self.assertRaises(HelperNotFoundError, Helper._check_output, ["not_a_command"])
        self.assertRaises(HelperNotFoundError, Helper._check_output, ["not_a_command"], require_success=True)

    def test_check_output_helpererror(self):
        """HelperError if executable fails and require_success is set."""
        with self.assertRaises(HelperError) as cm:
            Helper._check_output(["false"])
        self.assertEqual(cm.exception.errno, 1)

        Helper._check_output(["false"], require_success=False)

    def test_helper_not_found(self):
        """Make sure helper.path is None if find_executable fails."""
        Helper.find_executable = self.stub_find_executable
        self.assertEqual(self.helper.path, None)

    def test_install_helper_already_present(self):
        """Make sure a warning is logged when attempting to re-install."""
        self.helper._path = True
        self.helper.install_helper()
        self.assertLogged(**self.ALREADY_INSTALLED)

    def test_call_helper_install(self):
        """call_helper will call install_helper, which raises an error."""
        self.assertRaises(NotImplementedError, self.helper.call_helper, ["Hello!"])

    def test_call_helper_no_install(self):
        """If not installed, and user declines, raise HelperNotFoundError."""
        self.default_confirm_response = False
        self.assertRaises(HelperNotFoundError, self.helper.call_helper, ["Hello!"])

    def test_download_and_expand(self):
        """Validate the download_and_expand() context_manager."""
        # Remove our stub for this test only
        Helper.download_and_expand = self._download_and_expand
        try:
            with Helper.download_and_expand("https://github.com/glennmatthews/cot/archive/master.tar.gz") as directory:
                self.assertTrue(os.path.exists(directory))
                self.assertTrue(os.path.exists(os.path.join(directory, "cot-master")))
                self.assertTrue(os.path.exists(os.path.join(directory, "cot-master", "COT")))
                self.assertTrue(os.path.exists(os.path.join(directory, "cot-master", "COT", "tests")))
                self.assertTrue(os.path.exists(os.path.join(directory, "cot-master", "COT", "tests", "ut.py")))
        except ConnectionError:
            # unable to connect to github - might be an isolated environment
            self.fail("ConnectionError when trying to download from GitHub")
        # Temporary directory should be cleaned up when done
        self.assertFalse(os.path.exists(directory))