示例#1
0
    def test_get_project_not_used_when_project_names_hidden(self):
        response = Response()
        response.status_code = 0
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

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

        now = u(int(time.time()))
        entity = os.path.join(tempdir, 'git', 'emptyfile.txt')
        config = 'tests/samples/configs/good_config.cfg'

        args = ['--hide-project-names', '--file', entity, '--config', config, '--time', now]

        execute(args)
        self.assertHeartbeatSavedOffline()

        self.assertNotEquals('git', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
        self.assertEquals(None, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch'])
        proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
        self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])

        execute(args)

        self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
示例#2
0
    def test_svn_on_mac_without_xcode_tools_installed(self):
        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            with mock.patch('wakatime.projects.subversion.platform.system') as mock_system:
                mock_system.return_value = 'Darwin'

                with mock.patch('wakatime.projects.subversion.Popen.communicate') as mock_popen:
                    stdout = open('tests/samples/output/svn').read()
                    stderr = ''
                    mock_popen.return_value = DynamicIterable((stdout, stderr), raise_on_calls=[OSError('')])

                    self.shared(
                        expected_project=None,
                        entity='projects/svn/afolder/emptyfile.txt',
                    )
示例#3
0
    def test_svn_project_detected(self):
        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            with mock.patch('wakatime.projects.subversion.Subversion._has_xcode_tools') as mock_has_xcode:
                mock_has_xcode.return_value = True

                with mock.patch('wakatime.projects.subversion.Popen.communicate') as mock_popen:
                    stdout = open('tests/samples/output/svn').read()
                    stderr = ''
                    mock_popen.return_value = DynamicIterable((stdout, stderr), max_calls=1)

                    self.shared(
                        expected_project='svn',
                        entity='projects/svn/afolder/emptyfile.txt',
                    )
示例#4
0
    def test_svn_on_mac_with_xcode_tools_installed(self):
        response = Response()
        response.status_code = 0
        self.patched[
            'wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        now = u(int(time.time()))
        entity = 'tests/samples/projects/svn/afolder/emptyfile.txt'
        config = 'tests/samples/configs/good_config.cfg'

        args = ['--file', entity, '--config', config, '--time', now]

        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            with mock.patch('wakatime.projects.subversion.platform.system'
                            ) as mock_system:
                mock_system.return_value = 'Darwin'

                with mock.patch(
                        'wakatime.projects.subversion.Popen') as mock_popen:
                    stdout = open('tests/samples/output/svn').read()
                    stderr = ''

                    class Dynamic(object):
                        def __init__(self):
                            self.called = 0

                        def communicate(self):
                            self.called += 1
                            if self.called == 2:
                                return (stdout, stderr)

                        def wait(self):
                            if self.called == 1:
                                return 0

                    mock_popen.return_value = Dynamic()

                    execute(args)

        self.assertEquals(
            'svn',
            self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]
            ['project'])
示例#5
0
    def test_branch_used_when_project_names_hidden_but_branch_names_visible(
            self):
        response = Response()
        response.status_code = 0
        self.patched[
            'wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

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

        now = u(int(time.time()))
        entity = os.path.join(tempdir, 'git', 'emptyfile.txt')
        config = 'tests/samples/configs/show_branch_names.cfg'

        args = [
            '--hide-project-names', '--file', entity, '--config', config,
            '--time', now
        ]

        execute(args)
        self.assertHeartbeatSavedOffline()

        self.assertNotEquals(
            'git',
            self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]
            ['project'])
        self.assertNotEquals(
            None, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0]
            [0]['branch'])
        proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
        self.assertEquals(
            proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0]
            [0]['project'])

        execute(args)

        self.assertEquals(
            proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0]
            [0]['project'])
示例#6
0
    def test_svn_on_mac_without_xcode_tools_installed(self):
        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            with mock.patch('wakatime.projects.subversion.platform.system'
                            ) as mock_system:
                mock_system.return_value = 'Darwin'

                with mock.patch(
                        'wakatime.projects.subversion.Popen.communicate'
                ) as mock_popen:
                    stdout = open('tests/samples/output/svn').read()
                    stderr = ''
                    mock_popen.return_value = DynamicIterable(
                        (stdout, stderr), raise_on_calls=[OSError('')])

                    self.shared(
                        expected_project=None,
                        entity='projects/svn/afolder/emptyfile.txt',
                    )
示例#7
0
    def test_svn_project_detected(self):
        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            with mock.patch(
                    'wakatime.projects.subversion.Subversion._has_xcode_tools'
            ) as mock_has_xcode:
                mock_has_xcode.return_value = True

                with mock.patch(
                        'wakatime.projects.subversion.Popen.communicate'
                ) as mock_popen:
                    stdout = open('tests/samples/output/svn').read()
                    stderr = ''
                    mock_popen.return_value = DynamicIterable((stdout, stderr),
                                                              max_calls=1)

                    self.shared(
                        expected_project='svn',
                        entity='projects/svn/afolder/emptyfile.txt',
                    )
示例#8
0
    def test_svn_on_mac_with_xcode_tools_installed(self):
        response = Response()
        response.status_code = 0
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        now = u(int(time.time()))
        entity = 'tests/samples/projects/svn/afolder/emptyfile.txt'
        config = 'tests/samples/configs/good_config.cfg'

        args = ['--file', entity, '--config', config, '--time', now]

        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            with mock.patch('wakatime.projects.subversion.platform.system') as mock_system:
                mock_system.return_value = 'Darwin'

                with mock.patch('wakatime.projects.subversion.Popen') as mock_popen:
                    stdout = open('tests/samples/output/svn').read()
                    stderr = ''

                    class Dynamic(object):
                        def __init__(self):
                            self.called = 0

                        def communicate(self):
                            self.called += 1
                            if self.called == 2:
                                return (stdout, stderr)

                        def wait(self):
                            if self.called == 1:
                                return 0

                    mock_popen.return_value = Dynamic()

                    execute(args)

        self.assertEquals('svn', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])