예제 #1
0
class RepoStatsTest(unittest.TestCase):
    def setUp(self):
        self.repo_stats = RepoStats()
        self.repo_stats.changed = 1
        self.repo_stats.conflicted = 4

    def test_dirty(self):
        self.assertTrue(self.repo_stats.dirty)

    def test_simple(self):
        self.assertEqual(self.repo_stats.new, 0)

    def test_n_or_empty__empty(self):
        self.assertEqual(self.repo_stats.n_or_empty("changed"), u"")

    def test_n_or_empty__n(self):
        self.assertEqual(self.repo_stats.n_or_empty("conflicted"), u"4")

    def test_index(self):
        self.assertEqual(self.repo_stats["changed"], 1)
예제 #2
0
 def add_to_powerline(self):
     self.join()
     if not self.stats:
         if self.branch:
             bg = self.powerline.theme.REPO_CLEAN_BG
             fg = self.powerline.theme.REPO_CLEAN_FG
             if self.powerline.segment_conf("vcs", "show_symbol"):
                 symbol = RepoStats().symbols["git"] + " "
             else:
                 symbol = ""
             self.powerline.append(" " + symbol + self.branch + " ", fg, bg)
         return
     bg = self.powerline.theme.REPO_CLEAN_BG
     fg = self.powerline.theme.REPO_CLEAN_FG
     if self.stats.dirty:
         bg = self.powerline.theme.REPO_DIRTY_BG
         fg = self.powerline.theme.REPO_DIRTY_FG
     if self.powerline.segment_conf("vcs", "show_symbol"):
         symbol = RepoStats().symbols["git"] + " "
     else:
         symbol = ""
     self.powerline.append(" " + symbol + self.branch + " ", fg, bg)
     self.stats.add_to_powerline(self.powerline)
예제 #3
0
def parse_git_stats(status):
    stats = RepoStats()
    for statusline in status[1:]:
        code = statusline[:2]
        if code == '??':
            stats.new += 1
        elif code in ('DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU'):
            stats.conflicted += 1
        else:
            if code[1] != ' ':
                stats.changed += 1
            if code[0] != ' ':
                stats.staged += 1

    return stats
예제 #4
0
import unittest
import mock
import tempfile
import shutil
import sh
import powerline_shell.segments.fossil as fossil
from powerline_shell.utils import RepoStats
from ..testing_utils import dict_side_effect_fn

test_cases = {
    "EXTRA      new-file": RepoStats(new=1),
    "EDITED     modified-file": RepoStats(changed=1),
    "CONFLICT   conflicted-file": RepoStats(conflicted=1),
    "ADDED      added-file": RepoStats(staged=1),
}


class FossilTest(unittest.TestCase):
    def setUp(self):
        self.powerline = mock.MagicMock()
        self.powerline.segment_conf.side_effect = dict_side_effect_fn({
            ("vcs", "show_symbol"):
            False,
        })

        self.dirname = tempfile.mkdtemp()
        sh.cd(self.dirname)
        sh.fossil("init", "test.fossil")
        sh.fossil("open", "test.fossil")

        self.segment = fossil.Segment(self.powerline, {})
예제 #5
0
import unittest
import mock
import tempfile
import shutil
import sh
import powerline_shell.segments.bzr as bzr
from powerline_shell.utils import RepoStats
from ..testing_utils import dict_side_effect_fn

test_cases = ((["unknown:",
                "  new-file"], RepoStats(new=1)), (["added:", "  added-file"],
                                                   RepoStats(staged=1)),
              (["modified:", "  modified-file"], RepoStats(changed=1)),
              (["removed:", "  removed-file"], RepoStats(changed=1)),
              (["missing:", "  missing-file"],
               RepoStats(changed=1)), (["renamed:", "  renamed-file"],
                                       RepoStats(changed=1)),
              (["kind changed:", "  kind-changed-file"], RepoStats(changed=1)))


class BzrTest(unittest.TestCase):
    def setUp(self):
        self.powerline = mock.MagicMock()
        self.powerline.segment_conf.side_effect = dict_side_effect_fn({
            ("vcs", "show_symbol"):
            False,
        })

        self.dirname = tempfile.mkdtemp()
        sh.cd(self.dirname)
        sh.bzr("init-repo", ".")
예제 #6
0
import unittest
import mock
import tempfile
import shutil
import sh
import powerline_shell.segments.hg as hg
from powerline_shell.utils import RepoStats

test_cases = {
    "? new-file": RepoStats(new=1),
    "M modified-file": RepoStats(changed=1),
    "R removed-file": RepoStats(changed=1),
    "! missing-file": RepoStats(changed=1),
    "A added-file": RepoStats(staged=1),
}


class HgTest(unittest.TestCase):
    def setUp(self):
        self.powerline = mock.MagicMock()

        self.dirname = tempfile.mkdtemp()
        sh.cd(self.dirname)
        sh.hg("init", ".")

        self.segment = hg.Segment(self.powerline)

    def tearDown(self):
        shutil.rmtree(self.dirname)

    def _add_and_commit(self, filename):
예제 #7
0
 def setUp(self):
     self.repo_stats = RepoStats()
     self.repo_stats.changed = 1
     self.repo_stats.conflicted = 4