Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/host_mock.py

Issue 2663623003: Simplify the initialization of Git objects in Host. (Closed)
Patch Set: Remove second paragraph in comment about awesome windows git hack Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 24 matching lines...) Expand all
35 # New-style ports need to move down into webkitpy.common. 35 # New-style ports need to move down into webkitpy.common.
36 from webkitpy.layout_tests.builder_list import BuilderList 36 from webkitpy.layout_tests.builder_list import BuilderList
37 from webkitpy.layout_tests.port.factory import PortFactory 37 from webkitpy.layout_tests.port.factory import PortFactory
38 from webkitpy.layout_tests.port.test import add_unit_tests_to_mock_filesystem 38 from webkitpy.layout_tests.port.test import add_unit_tests_to_mock_filesystem
39 39
40 40
41 class MockHost(MockSystemHost): 41 class MockHost(MockSystemHost):
42 42
43 def __init__(self, 43 def __init__(self,
44 log_executive=False, 44 log_executive=False,
45 initialize_scm_by_default=True,
46 web=None, 45 web=None,
47 scm=None, 46 scm=None,
48 os_name=None, 47 os_name=None,
49 os_version=None, 48 os_version=None,
50 time_return_val=123): 49 time_return_val=123):
51 super(MockHost, self).__init__( 50 super(MockHost, self).__init__(
52 log_executive=log_executive, 51 log_executive=log_executive,
53 os_name=os_name, 52 os_name=os_name,
54 os_version=os_version, 53 os_version=os_version,
55 time_return_val=time_return_val) 54 time_return_val=time_return_val)
56 55
57 add_unit_tests_to_mock_filesystem(self.filesystem) 56 add_unit_tests_to_mock_filesystem(self.filesystem)
58 self.web = web or MockWeb() 57 self.web = web or MockWeb()
58 self._scm = scm
59 59
60 self._scm = scm
61 # TODO(qyearsley): we should never initialize the SCM by default, since
62 # the real object doesn't either. This has caused at least one bug
63 # (see bug 89498).
64 if initialize_scm_by_default:
65 self.initialize_scm()
66 self.buildbot = MockBuildBot() 60 self.buildbot = MockBuildBot()
67 61
68 # Note: We're using a real PortFactory here. Tests which don't wish to depend 62 # Note: We're using a real PortFactory here. Tests which don't wish to depend
69 # on the list of known ports should override this with a MockPortFactory . 63 # on the list of known ports should override this with a MockPortFactory .
70 self.port_factory = PortFactory(self) 64 self.port_factory = PortFactory(self)
71 65
72 self.builders = BuilderList(BUILDERS) 66 self.builders = BuilderList(BUILDERS)
73 67
74 def initialize_scm(self, patch_directories=None): 68 def scm(self, path=None):
69 if path:
70 return MockGit(cwd=path, filesystem=self.filesystem, executive=self. executive)
75 if not self._scm: 71 if not self._scm:
76 self._scm = MockGit(filesystem=self.filesystem, executive=self.execu tive) 72 self._scm = MockGit(filesystem=self.filesystem, executive=self.execu tive)
77 # Various pieces of code (wrongly) call filesystem.chdir(checkout_root). 73 # Various pieces of code (wrongly) call filesystem.chdir(checkout_root).
78 # Making the checkout_root exist in the mock filesystem makes that chdir not raise. 74 # Making the checkout_root exist in the mock filesystem makes that chdir not raise.
79 self.filesystem.maybe_make_directory(self._scm.checkout_root) 75 self.filesystem.maybe_make_directory(self._scm.checkout_root)
80
81 def scm(self):
82 return self._scm 76 return self._scm
83
84 def scm_for_path(self, path):
85 # FIXME: consider supporting more than one SCM so that we can do more co mprehensive testing.
86 self.initialize_scm()
87 return self._scm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698