| OLD | NEW | 
| (Empty) |  | 
 |   1 # Copyright 2016 The Chromium Authors. All rights reserved. | 
 |   2 # Use of this source code is governed by a BSD-style license that can be | 
 |   3 # found in the LICENSE file. | 
 |   4  | 
 |   5 import unittest | 
 |   6  | 
 |   7 from webkitpy.common.host_mock import MockHost | 
 |   8 from webkitpy.common.system.executive_mock import MockExecutive2 | 
 |   9 from webkitpy.w3c.test_exporter import TestExporter | 
 |  10 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub | 
 |  11  | 
 |  12  | 
 |  13 class TestExporterTest(unittest.TestCase): | 
 |  14  | 
 |  15     def test_stops_if_more_than_one_pr_is_in_flight(self): | 
 |  16         host = MockHost() | 
 |  17         wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) | 
 |  18  | 
 |  19         # TODO: make Exception more specific | 
 |  20         with self.assertRaises(Exception): | 
 |  21             TestExporter(host, wpt_github).run() | 
 |  22  | 
 |  23     def test_if_pr_exists_merges_it(self): | 
 |  24         host = MockHost() | 
 |  25         wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
    ) | 
 |  26         TestExporter(host, wpt_github).run() | 
 |  27  | 
 |  28         self.assertIn('merge_pull_request', wpt_github.calls) | 
 |  29  | 
 |  30     def test_merge_failure_errors_out(self): | 
 |  31         host = MockHost() | 
 |  32         wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
    , | 
 |  33                                    unsuccessful_merge=True) | 
 |  34  | 
 |  35         # TODO: make Exception more specific | 
 |  36         with self.assertRaises(Exception): | 
 |  37             TestExporter(host, wpt_github).run() | 
 |  38  | 
 |  39     def test_dry_run_stops_before_creating_pr(self): | 
 |  40         host = MockHost() | 
 |  41         host.executive = MockExecutive2(output='beefcafe') | 
 |  42         wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
    ) | 
 |  43         TestExporter(host, wpt_github, dry_run=True).run() | 
 |  44  | 
 |  45         # TODO: mock exportable_commits_since | 
 |  46         self.assertEqual(wpt_github.calls, ['in_flight_pull_requests']) | 
 |  47  | 
 |  48     def test_creates_pull_request_for_earliest_commit(self): | 
 |  49         host = MockHost() | 
 |  50  | 
 |  51         def mock_command(args): | 
 |  52             git_command = args[1] | 
 |  53             if git_command == 'rev-list': | 
 |  54                 return 'cafedad5\nfacebeef' | 
 |  55             elif git_command == 'footers': | 
 |  56                 return 'fake-cr-position' | 
 |  57             elif git_command == 'show': | 
 |  58                 if 'cafedad5' in args: | 
 |  59                     return 'newer fake text' | 
 |  60                 elif 'facebeef' in args: | 
 |  61                     return 'older fake text' | 
 |  62             else: | 
 |  63                 return '' | 
 |  64  | 
 |  65         host.executive = MockExecutive2(run_command_fn=mock_command) | 
 |  66         wpt_github = MockWPTGitHub(pull_requests=[]) | 
 |  67  | 
 |  68         TestExporter(host, wpt_github).run() | 
 |  69  | 
 |  70         self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p
    r']) | 
 |  71         self.assertEqual(wpt_github.pull_requests_created, | 
 |  72                          [('chromium-export-try', 'older fake text', 'older fake
     text')]) | 
| OLD | NEW |