Esempio n. 1
0
class ClassicModelTestCase(helper.GitRepositoryTestCase):
    """Tests interfaces used by the classic view."""

    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self, commit=False)
        self.model = MainModel(cwd=core.getcwd())

    def test_everything(self):
        """Test the MainModel.everything() method."""
        self.touch('other-file')
        everything = self.model.everything()

        self.assertTrue('A' in everything)
        self.assertTrue('B' in everything)
        self.assertTrue('other-file' in everything)

    def test_stage_paths_untracked(self):
        """Test stage_paths() with an untracked file."""
        core.makedirs('foo/bar')
        self.touch('foo/bar/baz')
        self.model.stage_paths(['foo'])

        self.assertTrue('foo/bar/baz' in self.model.staged)
        self.assertTrue('foo/bar/baz' not in self.model.modified)
        self.assertTrue('foo/bar/baz' not in self.model.untracked)

    def test_unstage_paths(self):
        """Test a simple usage of unstage_paths()."""
        self.commit_files()
        self.write_file('A', 'change')
        self.git('add', 'A')
        gitcmds.unstage_paths(['A'])
        self.model.update_status()

        self.assertTrue('A' not in self.model.staged)
        self.assertTrue('A' in self.model.modified)

    def test_unstage_paths_init(self):
        """Test unstage_paths() on the root commit."""
        gitcmds.unstage_paths(['A'])
        self.model.update_status()

        self.assertTrue('A' not in self.model.staged)
        self.assertTrue('A' in self.model.untracked)

    def test_unstage_paths_subdir(self):
        """Test unstage_paths() in a subdirectory."""
        self.git('commit', '-m', 'intitial commit')
        core.makedirs('foo/bar')
        self.touch('foo/bar/baz')
        self.git('add', 'foo/bar/baz')
        gitcmds.unstage_paths(['foo'])
        self.model.update_status()

        self.assertTrue('foo/bar/baz' in self.model.untracked)
        self.assertTrue('foo/bar/baz' not in self.model.staged)
Esempio n. 2
0
    def test_git_config(self):
        """Test cola.git.config()"""
        self.git('config', 'section.key', 'value')
        model = MainModel(cwd=core.getcwd())
        value = model.git.config('section.key', get=True)

        self.assertEqual(value, (0, 'value', ''))

        #  Test config_set
        model.config_set('section.bool', True)
        value = model.git.config('section.bool', get=True)

        self.assertEqual(value, (0, 'true', ''))
        model.config_set('section.bool', False)

        # Test config_dict
        config_dict = model.config_dict(local=True)

        self.assertEqual(config_dict['section_key'], 'value')
        self.assertEqual(config_dict['section_bool'], False)

        # Test config_dict --global
        global_dict = model.config_dict(local=False)

        self.assertEqual(type(global_dict), dict)
Esempio n. 3
0
class ClassicModelTestCase(helper.GitRepositoryTestCase):
    """Tests interfaces used by the classic view."""
    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self, commit=False)
        self.model = MainModel(cwd=core.getcwd())

    def test_everything(self):
        """Test the MainModel.everything() method."""
        self.touch('other-file')
        everything = self.model.everything()

        self.assertTrue('A' in everything)
        self.assertTrue('B' in everything)
        self.assertTrue('other-file' in everything)

    def test_stage_paths_untracked(self):
        """Test stage_paths() with an untracked file."""
        core.makedirs('foo/bar')
        self.touch('foo/bar/baz')
        self.model.stage_paths(['foo'])

        self.assertTrue('foo/bar/baz' in self.model.staged)
        self.assertTrue('foo/bar/baz' not in self.model.modified)
        self.assertTrue('foo/bar/baz' not in self.model.untracked)

    def test_unstage_paths(self):
        """Test a simple usage of unstage_paths()."""
        self.commit_files()
        self.write_file('A', 'change')
        self.git('add', 'A')
        gitcmds.unstage_paths(['A'])
        self.model.update_status()

        self.assertTrue('A' not in self.model.staged)
        self.assertTrue('A' in self.model.modified)

    def test_unstage_paths_init(self):
        """Test unstage_paths() on the root commit."""
        gitcmds.unstage_paths(['A'])
        self.model.update_status()

        self.assertTrue('A' not in self.model.staged)
        self.assertTrue('A' in self.model.untracked)

    def test_unstage_paths_subdir(self):
        """Test unstage_paths() in a subdirectory."""
        self.git('commit', '-m', 'intitial commit')
        core.makedirs('foo/bar')
        self.touch('foo/bar/baz')
        self.git('add', 'foo/bar/baz')
        gitcmds.unstage_paths(['foo'])
        self.model.update_status()

        self.assertTrue('foo/bar/baz' in self.model.untracked)
        self.assertTrue('foo/bar/baz' not in self.model.staged)
Esempio n. 4
0
    def test_git_config(self):
        """Test cola.git.config()"""
        self.git('config', 'section.key', 'value')
        model = MainModel(cwd=core.getcwd())
        value = model.git.config('section.key', get=True)

        self.assertEqual(value, (0, 'value', ''))

        #  Test config_set
        model.config_set('section.bool', True)
        value = model.git.config('section.bool', get=True)

        self.assertEqual(value, (0, 'true', ''))
        model.config_set('section.bool', False)

        # Test config_dict
        config_dict = model.config_dict(local=True)

        self.assertEqual(config_dict['section_key'], 'value')
        self.assertEqual(config_dict['section_bool'], False)

        # Test config_dict --global
        global_dict = model.config_dict(local=False)

        self.assertEqual(type(global_dict), dict)
Esempio n. 5
0
    def test_git_commit(self):
        """Test running 'git commit' via cola.git"""
        self.write_file('A', 'A')
        self.write_file('B', 'B')
        self.git('add', 'A', 'B')

        model = MainModel(cwd=core.getcwd())
        model.git.commit(m='commit test')
        log = self.git('log', '--pretty=oneline')

        self.assertEqual(len(log.splitlines()), 1)
Esempio n. 6
0
    def test_git_commit(self):
        """Test running 'git commit' via cola.git"""
        self.shell("""
            echo A > A
            echo B > B
            git add A B
            """)

        model = MainModel(cwd=os.getcwd())
        model.git.commit(m='commit test')
        log = helper.pipe('git log --pretty=oneline | wc -l')

        self.assertEqual(log.strip(), '1')
Esempio n. 7
0
class ClassicModelTestCase(helper.GitRepositoryTestCase):
    """Tests interfaces used by the classic view."""

    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self, commit=False)
        self.model = MainModel(cwd=os.getcwd())

    def test_everything(self):
        """Test the MainModel.everything() method."""
        self.shell("touch other-file")
        everything = self.model.everything()

        self.assertTrue("A" in everything)
        self.assertTrue("B" in everything)
        self.assertTrue("other-file" in everything)

    def test_stage_paths_untracked(self):
        """Test stage_paths() with an untracked file."""
        self.shell(
            """
            mkdir -p foo/bar &&
            touch foo/bar/baz
        """
        )
        self.model.stage_paths(["foo"])

        self.assertTrue("foo/bar/baz" in self.model.staged)
        self.assertTrue("foo/bar/baz" not in self.model.modified)
        self.assertTrue("foo/bar/baz" not in self.model.untracked)

    def test_unstage_paths(self):
        """Test a simple usage of unstage_paths()."""
        self.shell(
            """
            git commit -m'initial commit' > /dev/null
            echo change > A &&
            git add A
        """
        )
        gitcmds.unstage_paths(["A"])
        self.model.update_status()

        self.assertTrue("A" not in self.model.staged)
        self.assertTrue("A" in self.model.modified)

    def test_unstage_paths_init(self):
        """Test unstage_paths() on the root commit."""
        gitcmds.unstage_paths(["A"])
        self.model.update_status()

        self.assertTrue("A" not in self.model.staged)
        self.assertTrue("A" in self.model.untracked)

    def test_unstage_paths_subdir(self):
        """Test unstage_paths() in a subdirectory."""
        self.shell("git commit -m'initial commit' > /dev/null")
        self.shell(
            """
            mkdir -p foo/bar &&
            touch foo/bar/baz &&
            git add foo/bar/baz
        """
        )
        gitcmds.unstage_paths(["foo"])
        self.model.update_status()

        self.assertTrue("foo/bar/baz" in self.model.untracked)
        self.assertTrue("foo/bar/baz" not in self.model.staged)
Esempio n. 8
0
 def setUp(self):
     helper.GitRepositoryTestCase.setUp(self, commit=False)
     self.model = MainModel(cwd=os.getcwd())
Esempio n. 9
0
 def setUp(self):
     helper.GitRepositoryTestCase.setUp(self)
     self.model = MainModel(cwd=core.getcwd())
Esempio n. 10
0
class MainModelTestCase(helper.GitRepositoryTestCase):
    """Tests the MainModel class."""

    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self)
        self.model = MainModel(cwd=core.getcwd())

    def test_project(self):
        """Test the 'project' attribute."""
        project = os.path.basename(self.test_path())
        self.assertEqual(self.model.project, project)

    def test_local_branches(self):
        """Test the 'local_branches' attribute."""
        self.model.update_status()
        self.assertEqual(self.model.local_branches, ['master'])

    def test_remote_branches(self):
        """Test the 'remote_branches' attribute."""
        self.model.update_status()
        self.assertEqual(self.model.remote_branches, [])

        self.git('remote', 'add', 'origin', '.')
        self.git('fetch', 'origin')
        self.model.update_status()
        self.assertEqual(self.model.remote_branches, ['origin/master'])

    def test_modified(self):
        """Test the 'modified' attribute."""
        self.write_file('A', 'change')
        self.model.update_status()
        self.assertEqual(self.model.modified, ['A'])

    def test_unstaged(self):
        """Test the 'unstaged' attribute."""
        self.write_file('A', 'change')
        self.write_file('C', 'C')
        self.model.update_status()
        self.assertEqual(self.model.unstaged, ['A', 'C'])

    def test_untracked(self):
        """Test the 'untracked' attribute."""
        self.write_file('C', 'C')
        self.model.update_status()
        self.assertEqual(self.model.untracked, ['C'])

    def test_remotes(self):
        """Test the 'remote' attribute."""
        self.git('remote', 'add', 'origin', '.')
        self.model.update_status()
        self.assertEqual(self.model.remotes, ['origin'])

    def test_currentbranch(self):
        """Test the 'currentbranch' attribute."""
        self.git('checkout', '-b', 'test')
        self.model.update_status()
        self.assertEqual(self.model.currentbranch, 'test')

    def test_tags(self):
        """Test the 'tags' attribute."""
        self.git('tag', 'test')
        self.model.update_status()
        self.assertEqual(self.model.tags, ['test'])
Esempio n. 11
0
class MainModelTestCase(helper.GitRepositoryTestCase):
    """Tests the MainModel class."""

    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self)
        self.model = MainModel(cwd=os.getcwd())

    def test_project(self):
        """Test the 'project' attribute."""
        project = os.path.basename(self.test_path())
        self.assertEqual(self.model.project, project)

    def test_local_branches(self):
        """Test the 'local_branches' attribute."""
        self.model.update_status()
        self.assertEqual(self.model.local_branches, ['master'])

    def test_remote_branches(self):
        """Test the 'remote_branches' attribute."""
        self.model.update_status()
        self.assertEqual(self.model.remote_branches, [])

        self.shell("""
                git remote add origin .
                git fetch origin > /dev/null 2>&1
        """)
        self.model.update_status()
        self.assertEqual(self.model.remote_branches, ['origin/master'])

    def test_modified(self):
        """Test the 'modified' attribute."""
        self.shell('echo change > A')
        self.model.update_status()
        self.assertEqual(self.model.modified, ['A'])

    def test_unstaged(self):
        """Test the 'unstaged' attribute."""
        self.shell('echo change > A')
        self.shell('echo C > C')
        self.model.update_status()
        self.assertEqual(self.model.unstaged, ['A', 'C'])

    def test_untracked(self):
        """Test the 'untracked' attribute."""
        self.shell('echo C > C')
        self.model.update_status()
        self.assertEqual(self.model.untracked, ['C'])

    def test_remotes(self):
        """Test the 'remote' attribute."""
        self.shell('git remote add origin .')
        self.model.update_status()
        self.assertEqual(self.model.remotes, ['origin'])

    def test_currentbranch(self):
        """Test the 'currentbranch' attribute."""
        self.shell('git checkout -b test > /dev/null 2>&1')
        self.model.update_status()
        self.assertEqual(self.model.currentbranch, 'test')

    def test_tags(self):
        """Test the 'tags' attribute."""
        self.shell('git tag test')
        self.model.update_status()
        self.assertEqual(self.model.tags, ['test'])
Esempio n. 12
0
class MainModelTestCase(helper.GitRepositoryTestCase):
    """Tests the MainModel class."""
    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self)
        self.model = MainModel(cwd=os.getcwd())

    def test_project(self):
        """Test the 'project' attribute."""
        project = os.path.basename(self.test_path())
        self.assertEqual(self.model.project, project)

    def test_local_branches(self):
        """Test the 'local_branches' attribute."""
        self.model.update_status()
        self.assertEqual(self.model.local_branches, ['master'])

    def test_remote_branches(self):
        """Test the 'remote_branches' attribute."""
        self.model.update_status()
        self.assertEqual(self.model.remote_branches, [])

        self.shell("""
                git remote add origin .
                git fetch origin > /dev/null 2>&1
        """)
        self.model.update_status()
        self.assertEqual(self.model.remote_branches, ['origin/master'])

    def test_modified(self):
        """Test the 'modified' attribute."""
        self.shell('echo change > A')
        self.model.update_status()
        self.assertEqual(self.model.modified, ['A'])

    def test_unstaged(self):
        """Test the 'unstaged' attribute."""
        self.shell('echo change > A')
        self.shell('echo C > C')
        self.model.update_status()
        self.assertEqual(self.model.unstaged, ['A', 'C'])

    def test_untracked(self):
        """Test the 'untracked' attribute."""
        self.shell('echo C > C')
        self.model.update_status()
        self.assertEqual(self.model.untracked, ['C'])

    def test_remotes(self):
        """Test the 'remote' attribute."""
        self.shell('git remote add origin .')
        self.model.update_status()
        self.assertEqual(self.model.remotes, ['origin'])

    def test_currentbranch(self):
        """Test the 'currentbranch' attribute."""
        self.shell('git checkout -b test > /dev/null 2>&1')
        self.model.update_status()
        self.assertEqual(self.model.currentbranch, 'test')

    def test_tags(self):
        """Test the 'tags' attribute."""
        self.shell('git tag test')
        self.model.update_status()
        self.assertEqual(self.model.tags, ['test'])
Esempio n. 13
0
 def setUp(self):
     helper.GitRepositoryTestCase.setUp(self, commit=False)
     self.model = MainModel(self.context, cwd=core.getcwd())
Esempio n. 14
0
 def test_git_config(self):
     """Test cola.git.config()"""
     self.git('config', 'section.key', 'value')
     model = MainModel(self.context, cwd=core.getcwd())
     value = model.git.config('section.key', get=True)
     self.assertEqual(value, (0, 'value', ''))
Esempio n. 15
0
 def setUp(self):
     helper.GitRepositoryTestCase.setUp(self, commit=False)
     self.model = MainModel(cwd=os.getcwd())
Esempio n. 16
0
class ClassicModelTestCase(helper.GitRepositoryTestCase):
    """Tests interfaces used by the classic view."""
    def setUp(self):
        helper.GitRepositoryTestCase.setUp(self, commit=False)
        self.model = MainModel(cwd=os.getcwd())

    def test_everything(self):
        """Test the MainModel.everything() method."""
        self.shell('touch other-file')
        everything = self.model.everything()

        self.assertTrue('A' in everything)
        self.assertTrue('B' in everything)
        self.assertTrue('other-file' in everything)

    def test_stage_paths_untracked(self):
        """Test stage_paths() with an untracked file."""
        self.shell("""
            mkdir -p foo/bar &&
            touch foo/bar/baz
        """)
        self.model.stage_paths(['foo'])

        self.assertTrue('foo/bar/baz' in self.model.staged)
        self.assertTrue('foo/bar/baz' not in self.model.modified)
        self.assertTrue('foo/bar/baz' not in self.model.untracked)

    def test_unstage_paths(self):
        """Test a simple usage of unstage_paths()."""
        self.shell("""
            git commit -m'initial commit' > /dev/null
            echo change > A &&
            git add A
        """)
        gitcmds.unstage_paths(['A'])
        self.model.update_status()

        self.assertTrue('A' not in self.model.staged)
        self.assertTrue('A' in self.model.modified)

    def test_unstage_paths_init(self):
        """Test unstage_paths() on the root commit."""
        gitcmds.unstage_paths(['A'])
        self.model.update_status()

        self.assertTrue('A' not in self.model.staged)
        self.assertTrue('A' in self.model.untracked)

    def test_unstage_paths_subdir(self):
        """Test unstage_paths() in a subdirectory."""
        self.shell("git commit -m'initial commit' > /dev/null")
        self.shell("""
            mkdir -p foo/bar &&
            touch foo/bar/baz &&
            git add foo/bar/baz
        """)
        gitcmds.unstage_paths(['foo'])
        self.model.update_status()

        self.assertTrue('foo/bar/baz' in self.model.untracked)
        self.assertTrue('foo/bar/baz' not in self.model.staged)