Пример #1
0
    def test_git_path_from_gitdir_link_file_handles_invalid_link(self, logs):
        logging.disable(logging.NOTSET)

        tempdir = tempfile.mkdtemp()
        shutil.copytree('tests/samples/projects/git-with-submodule', os.path.join(tempdir, 'git'))
        shutil.move(os.path.join(tempdir, 'git', 'asubmodule', 'dot_git'), os.path.join(tempdir, 'git', 'asubmodule', '.git'))

        path = os.path.join(tempdir, 'git', 'asubmodule')

        git = Git(None)
        result = git._path_from_gitdir_link_file(path)

        expected = None
        self.assertEquals(expected, result)
        self.assertNothingPrinted()
        self.assertNothingLogged(logs)
Пример #2
0
    def test_git_path_from_gitdir_link_file_handles_invalid_link(self, logs):
        logging.disable(logging.NOTSET)

        tempdir = tempfile.mkdtemp()
        shutil.copytree('tests/samples/projects/git-with-submodule',
                        os.path.join(tempdir, 'git'))
        shutil.move(os.path.join(tempdir, 'git', 'asubmodule', 'dot_git'),
                    os.path.join(tempdir, 'git', 'asubmodule', '.git'))

        path = os.path.join(tempdir, 'git', 'asubmodule')

        git = Git(None)
        result = git._path_from_gitdir_link_file(path)

        expected = None
        self.assertEquals(expected, result)
        self.assertNothingPrinted()
        self.assertNothingLogged(logs)
Пример #3
0
    def test_git_path_from_gitdir_link_file_handles_exceptions(self, logs):
        logging.disable(logging.NOTSET)

        tempdir = tempfile.mkdtemp()
        shutil.copytree('tests/samples/projects/git-with-submodule', os.path.join(tempdir, 'git'))
        shutil.move(os.path.join(tempdir, 'git', 'dot_git'), os.path.join(tempdir, 'git', '.git'))
        shutil.move(os.path.join(tempdir, 'git', 'asubmodule', 'dot_git'), os.path.join(tempdir, 'git', 'asubmodule', '.git'))

        self.orig_open = open
        self.count = 0

        with mock.patch('wakatime.projects.git.open') as mock_open:

            def side_effect_function(*args, **kwargs):
                self.count += 1
                if self.count <= 1:
                    raise IOError('')
                return self.orig_open(*args, **kwargs)

            mock_open.side_effect = side_effect_function

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._path_from_gitdir_link_file(path)

            expected = os.path.realpath(os.path.join(tempdir, 'git', '.git', 'modules', 'asubmodule'))
            self.assertEquals(expected, result)
            self.assertNothingPrinted()
            self.assertNothingLogged(logs)

        with mock.patch('wakatime.projects.git.open') as mock_open:
            mock_open.side_effect = UnicodeDecodeError('utf8', ''.encode('utf8'), 0, 0, '')

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._path_from_gitdir_link_file(path)

            self.assertIsNone(result)
            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'UnicodeDecodeError'
            self.assertIn(expected, actual)

        with mock.patch('wakatime.projects.git.open') as mock_open:
            mock_open.side_effect = IOError('')

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._path_from_gitdir_link_file(path)

            self.assertIsNone(result)
            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'OSError' if self.isPy33OrNewer else 'IOError'
            self.assertIn(expected, actual)
Пример #4
0
    def test_git_find_path_from_submodule_handles_exceptions(self, logs):
        logging.disable(logging.NOTSET)

        tempdir = tempfile.mkdtemp()
        shutil.copytree('tests/samples/projects/git-with-submodule',
                        os.path.join(tempdir, 'git'))
        shutil.move(os.path.join(tempdir, 'git', 'dot_git'),
                    os.path.join(tempdir, 'git', '.git'))
        shutil.move(os.path.join(tempdir, 'git', 'asubmodule', 'dot_git'),
                    os.path.join(tempdir, 'git', 'asubmodule', '.git'))

        with mock.patch('wakatime.projects.git.open') as mock_open:
            mock_open.side_effect = UnicodeDecodeError('utf8',
                                                       ''.encode('utf8'), 0, 0,
                                                       '')

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._find_path_from_submodule(path)

            self.assertIsNone(result)
            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'UnicodeDecodeError'
            self.assertIn(expected, actual)

        with mock.patch('wakatime.projects.git.open') as mock_open:
            mock_open.side_effect = IOError('')

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._find_path_from_submodule(path)

            self.assertIsNone(result)
            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'OSError' if self.isPy33OrNewer else 'IOError'
            self.assertIn(expected, actual)
Пример #5
0
    def test_git_path_from_gitdir_link_file_handles_exceptions(self, logs):
        logging.disable(logging.NOTSET)

        tempdir = tempfile.mkdtemp()
        shutil.copytree('tests/samples/projects/git-with-submodule',
                        os.path.join(tempdir, 'git'))
        shutil.move(os.path.join(tempdir, 'git', 'dot_git'),
                    os.path.join(tempdir, 'git', '.git'))
        shutil.move(os.path.join(tempdir, 'git', 'asubmodule', 'dot_git'),
                    os.path.join(tempdir, 'git', 'asubmodule', '.git'))

        self.orig_open = open
        self.count = 0

        with mock.patch('wakatime.projects.git.open') as mock_open:

            def side_effect_function(*args, **kwargs):
                self.count += 1
                if self.count <= 1:
                    raise IOError('')
                return self.orig_open(*args, **kwargs)

            mock_open.side_effect = side_effect_function

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._path_from_gitdir_link_file(path)

            expected = os.path.realpath(
                os.path.join(tempdir, 'git', '.git', 'modules', 'asubmodule'))
            self.assertEquals(expected, result)
            self.assertNothingPrinted()
            self.assertNothingLogged(logs)

        with mock.patch('wakatime.projects.git.open') as mock_open:
            mock_open.side_effect = UnicodeDecodeError('utf8',
                                                       ''.encode('utf8'), 0, 0,
                                                       '')

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._path_from_gitdir_link_file(path)

            self.assertIsNone(result)
            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'UnicodeDecodeError'
            self.assertIn(expected, actual)

        with mock.patch('wakatime.projects.git.open') as mock_open:
            mock_open.side_effect = IOError('')

            git = Git(None)
            path = os.path.join(tempdir, 'git', 'asubmodule')
            result = git._path_from_gitdir_link_file(path)

            self.assertIsNone(result)
            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'OSError' if self.isPy33OrNewer else 'IOError'
            self.assertIn(expected, actual)