Пример #1
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)
Пример #2
0
    def test_git_find_path_from_submodule(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'))

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

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

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