コード例 #1
0
def get_test_cases(patches, dbdir):
    """
    Return test cases by querying layout according list of patch files.
    Args:
        patches: List of patches, they can be local files or remote urls
        dbdir:   Path to the kpet-db
    """
    tmpdir = tempfile.mkdtemp(suffix='kpet')
    try:
        patches = utils.patch2localfile(patches, tmpdir)
        src_files = targeted.get_src_files(patches)
        return sorted(targeted.get_test_cases(src_files, dbdir))
    finally:
        shutil.rmtree(tmpdir)
コード例 #2
0
 def test_patch2localfile(self):
     """
     Check remote urls are fetched and saved in local files, check local
     files are untouched and if execption is raised when request response is
     invalid.
     """
     tmpdir = tempfile.mkdtemp()
     patches = utils.patch2localfile(['/patch', '/another/patch'], tmpdir)
     self.assertListEqual(['/patch', '/another/patch'], patches)
     with mock.patch('requests.get') as mock_request_get:
         response = mock.Mock()
         response.content = b'some content'
         mock_request_get.return_value = response
         patches = utils.patch2localfile(
             ['http://mypatch.org', '/localfile'], tmpdir)
         mock_request_get.assert_called_with('http://mypatch.org')
         with open(patches[0]) as file_handler:
             file_content = file_handler.read()
         self.assertEqual('some content', file_content)
         response.raise_for_status.side_effect = requests.HTTPError
         self.assertRaises(requests.HTTPError, utils.patch2localfile,
                           ['http://mypatch.org', '/localfile'], tmpdir)
     shutil.rmtree(tmpdir)
コード例 #3
0
def get_test_cases(patches, dbdir, pw_cookie=None):
    """
    Return test cases by querying layout according list of patch files.
    Args:
        patches:   List of patches, they can be local files or remote urls
        dbdir:     Path to the kpet-db
        pw_cookie: Session cookie to Patchwork instance if login is required,
                   None otherwise
    """
    tmpdir = tempfile.mkdtemp(suffix='kpet')
    try:
        patches = utils.patch2localfile(patches, tmpdir, pw_cookie)
        src_files = targeted.get_src_files(patches)
        return sorted(targeted.get_test_cases(src_files, dbdir))
    finally:
        shutil.rmtree(tmpdir)