예제 #1
0
 def file(self, path):
     with Process(['git', 'log', '--oneline', '--no-abbrev-commit', path],
                  self.workdir) as subproc:
         while True:
             line = subproc.readline(timeout=None)
             if not line:
                 break
             commit, log = line.split(' ', 1)
             yield commit
예제 #2
0
 def test_process_annex_metadata_batch(self):
     """Process should be able to read one line"""
     with Process(
         ['git', 'annex', 'metadata', '--batch', '--json'],
             str(self.tempdir),
     ) as proc:
         proc.writeline('{"key":"SHA256E-s0--0"}')
         line = proc.readline(timeout=1)
         self.assertEqual(line, ('{'
                                 '"command":"metadata",'
                                 '"note":"",'
                                 '"success":true,'
                                 '"key":"SHA256E-s0--0",'
                                 '"file":null,'
                                 '"fields":{}'
                                 '}'))
         line_call = proc('{"key":"SHA256E-s0--0"}')
         self.assertEqual(line_call, line)
예제 #3
0
    def test_process_matches_popen_communicate(self):
        """Process.communicate should work as Popen.communicate does"""
        with Process(
            ['git', 'config', '-l'],
            str(self.tempdir),
        ) as proc:
            result_proc = proc.communicate()

        with subprocess.Popen(
            ['git', 'config', '-l'],
            cwd=str(self.tempdir),
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True,
            bufsize=1,
        ) as popen:
            result_popen = popen.communicate()

        self.assertEqual(result_proc, result_popen)
 def test_process_annex_info_batch(self):
     """Process should be able to read multiple lines"""
     with Process(
         ['git', 'annex', 'info', '--batch'],
             str(self.tempdir),
     ) as proc:
         proc.writeline('here')
         lines_here = proc.readlines(timeout=1, count=2)
         self.assertEqual(lines_here, [
             'remote annex keys: 0',
             'remote annex size: 0 bytes',
         ])
         proc.writeline('.')
         lines_dot = proc.readlines(timeout=1, count=7)
         self.assertEqual(lines_dot, [
             'directory: .',
             'local annex keys: 0',
             'local annex size: 0 bytes',
             'annexed files in working tree: 0',
             'size of annexed files in working tree: 0 bytes',
             'numcopies stats: ',
             'repositories containing these files: 0',
         ])
예제 #5
0
    def test_process_git_status(self):
        """Process should be able to read whole output"""
        with Process(['git', 'status'], str(self.tempdir)) as proc:
            stdout = proc.readlines(timeout=1, count=None)

        try:
            self.assertEqual(stdout, [
                'On branch master',
                '',
                'Initial commit',
                '',
                'nothing to commit (create/copy files '
                + 'and use "git add" to track)',
            ])

        except AssertionError:
            self.assertEqual(stdout, [
                'On branch master',
                '',
                'No commits yet',
                '',
                'nothing to commit (create/copy files '
                + 'and use "git add" to track)',
            ])