Пример #1
0
    def test_files(self):

        new_file = 'a.rst'

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, new_file),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # before commit files
        ctx = self.get_ctx()
        for f in self.repo_files:
            self.assertTrue(f in ctx.files, 'file not found in stable state: '
                            '%s' % f)
        self.assertFalse(new_file in ctx.files, 'stable state is '
                         'listing uncommited file.')

        git_commit(self.repo, self.tree, [new_file], [self.old_commit])

        # after commit files
        ctx = self.get_ctx()
        for f in self.repo_files + [new_file]:
            self.assertTrue(f in ctx.files, 'file not found in stable '
                            'state: %s' % f)
Пример #2
0
    def test_filectx_needs_reload(self):

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, 'a.rst'),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')
        self.repo.index.add('a.rst')
        self.repo.index.write()

        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        self.assertTrue(ctx.filectx_needs_reload(filectx))

        with codecs.open(os.path.join(self.repo_path, 'a.rst'),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # should always be true
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        git_commit(self.repo, self.tree, ['a.rst'], [self.old_commit])

        # should need a reload now, after the commit
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        # reload
        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        # should still need a reload, right after the reload
        self.assertTrue(ctx.filectx_needs_reload(filectx))
Пример #3
0
    def test_filectx_needs_reload(self):

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, 'a.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')
        self.repo.index.add('a.rst')
        self.repo.index.write()

        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        self.assertTrue(ctx.filectx_needs_reload(filectx))

        with codecs.open(os.path.join(self.repo_path, 'a.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # should always be true
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        git_commit(self.repo, self.tree, ['a.rst'], [self.old_commit])

        # should need a reload now, after the commit
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        # reload
        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        # should still need a reload, right after the reload
        self.assertTrue(ctx.filectx_needs_reload(filectx))
Пример #4
0
    def test_filectx_needs_reload(self):

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, 'a.rst'),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        self.old_commit = git_commit(self.repo, self.tree, ['a.rst'],
                                     [self.old_commit])

        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        self.assertFalse(ctx.filectx_needs_reload(filectx))

        with codecs.open(os.path.join(self.repo_path, 'a.rst'),
                         'a',
                         encoding='utf-8') as fp:
            fp.write('lol\n')

        # should still be false
        self.assertFalse(ctx.filectx_needs_reload(filectx))

        git_commit(self.repo, self.tree, ['a.rst'], [self.old_commit])

        # should need a reload now, after the commit
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        # reload
        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        # shouldn't need a reload again
        self.assertFalse(ctx.filectx_needs_reload(filectx))
Пример #5
0
    def test_files(self):

        new_file = 'a.rst'

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, new_file), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')
        self.repo.index.add(new_file)
        self.repo.index.write()

        # before commit files
        ctx = self.get_ctx()
        for f in self.repo_files + [new_file]:
            self.assertTrue(f in ctx.files, 'file not found in variable '
                            'state: %s' % f)
        self.assertTrue(new_file in ctx.files, 'variable state is not '
                        'listing uncommited file.')

        git_commit(self.repo, self.tree, [new_file], [self.old_commit])

        # after commit files
        ctx = self.get_ctx()
        for f in self.repo_files + [new_file]:
            self.assertTrue(f in ctx.files, 'file not found in variable'
                            'state: %s' % f)
Пример #6
0
    def test_filectx_needs_reload(self):

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, 'a.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        self.old_commit = git_commit(self.repo, self.tree, ['a.rst'],
                                     [self.old_commit])

        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        self.assertFalse(ctx.filectx_needs_reload(filectx))

        with codecs.open(os.path.join(self.repo_path, 'a.rst'), 'a',
                         encoding='utf-8') as fp:
            fp.write('lol\n')

        # should still be false
        self.assertFalse(ctx.filectx_needs_reload(filectx))

        git_commit(self.repo, self.tree, ['a.rst'], [self.old_commit])

        # should need a reload now, after the commit
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        # reload
        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        # shouldn't need a reload again
        self.assertFalse(ctx.filectx_needs_reload(filectx))
Пример #7
0
 def test_date_and_mdate(self):
     ctx = FileCtx(self.repo, self.changectx, self.file_name)
     time.sleep(1)
     self.assertTrue(ctx.date < time.time())
     self.assertTrue(ctx.mdate is None)
     old_date = ctx.date
     time.sleep(1)
     with codecs.open(self.file_path, 'a', encoding='utf-8') as fp:
         fp.write('foo\n')
     git_commit(self.repo, self.tree, [self.file_name], [self.last_commit])
     ctx = FileCtx(self.repo, self.changectx, self.file_name)
     self.assertEqual(ctx.date, old_date)
     self.assertTrue(ctx.mdate > old_date)
Пример #8
0
 def test_date_and_mdate(self):
     ctx = FileCtx(self.repo, self.changectx, self.file_name)
     time.sleep(1)
     self.assertTrue(ctx.date < time.time())
     self.assertTrue(ctx.mdate is None)
     old_date = ctx.date
     time.sleep(1)
     with codecs.open(self.file_path, 'a', encoding='utf-8') as fp:
         fp.write('foo\n')
     git_commit(self.repo, self.tree, [self.file_name], [self.last_commit])
     ctx = FileCtx(self.repo, self.changectx, self.file_name)
     self.assertEqual(ctx.date, old_date)
     self.assertTrue(ctx.mdate > old_date)
Пример #9
0
 def setUp(self):
     self.repo_path = mkdtemp()
     init_repository(self.repo_path, False)
     self.repo = Repository(self.repo_path)
     self.file_name = 'foo.rst'
     self.file_path = os.path.join(self.repo_path, self.file_name)
     with codecs.open(self.file_path, 'w', encoding='utf-8') as fp:
         fp.write('test\n')
     self.tree = self.repo.TreeBuilder()
     self.last_commit = git_commit(self.repo, self.tree, [self.file_name])
     self.changectx = self.repo.head
Пример #10
0
 def setUp(self):
     self.repo_path = mkdtemp()
     init_repository(self.repo_path, False)
     self.repo = Repository(self.repo_path)
     self.file_name = 'foo.rst'
     self.file_path = os.path.join(self.repo_path, self.file_name)
     with codecs.open(self.file_path, 'w', encoding='utf-8') as fp:
         fp.write('test\n')
     self.tree = self.repo.TreeBuilder()
     self.last_commit = git_commit(self.repo, self.tree, [self.file_name])
     self.changectx = self.repo.head
Пример #11
0
    def setUp(self):
        self.repo_path = mkdtemp()
        init_repository(self.repo_path, False)
        self.repo = Repository(self.repo_path)

        # create files and commit
        self.sign = Signature('foo', '*****@*****.**')
        self.repo_files = ['a%i.rst' % i for i in range(5)]
        for i in self.repo_files:
            with codecs.open(os.path.join(self.repo_path, i), 'w',
                             encoding='utf-8') as fp:
                fp.write('dumb file %s\n' % i)
        self.tree = self.repo.TreeBuilder()
        self.old_commit = git_commit(self.repo, self.tree, self.repo_files)
Пример #12
0
    def setUp(self):
        self.repo_path = mkdtemp()
        init_repository(self.repo_path, False)
        self.repo = Repository(self.repo_path)

        # create files and commit
        self.sign = Signature('foo', '*****@*****.**')
        self.repo_files = ['a%i.rst' % i for i in range(5)]
        for i in self.repo_files:
            with codecs.open(os.path.join(self.repo_path, i),
                             'w',
                             encoding='utf-8') as fp:
                fp.write('dumb file %s\n' % i)
        self.tree = self.repo.TreeBuilder()
        self.old_commit = git_commit(self.repo, self.tree, self.repo_files)