OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import platform | 29 import platform |
30 import sys | 30 import sys |
31 import unittest | 31 import unittest |
32 | 32 |
33 from webkitpy.common.system.executive import Executive | 33 from webkitpy.common.system.executive import Executive |
34 from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2 | 34 from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2 |
| 35 from webkitpy.common.system.filesystem import FileSystem |
| 36 from webkitpy.common.system.filesystem_mock import MockFileSystem |
35 from webkitpy.common.system.platforminfo import PlatformInfo | 37 from webkitpy.common.system.platforminfo import PlatformInfo |
36 | 38 |
37 | 39 |
38 def fake_sys(platform_str='darwin', windows_version_tuple=None): | 40 def fake_sys(platform_str='darwin', windows_version_tuple=None): |
39 | 41 |
40 class FakeSysModule(object): | 42 class FakeSysModule(object): |
41 platform = platform_str | 43 platform = platform_str |
42 if windows_version_tuple: | 44 if windows_version_tuple: |
43 getwindowsversion = lambda x: windows_version_tuple | 45 getwindowsversion = lambda x: windows_version_tuple |
44 | 46 |
(...skipping 15 matching lines...) Expand all Loading... |
60 return FakePlatformModule() | 62 return FakePlatformModule() |
61 | 63 |
62 | 64 |
63 def fake_executive(output=None): | 65 def fake_executive(output=None): |
64 if output: | 66 if output: |
65 return MockExecutive2(output=output) | 67 return MockExecutive2(output=output) |
66 return MockExecutive2(exception=SystemError) | 68 return MockExecutive2(exception=SystemError) |
67 | 69 |
68 | 70 |
69 class TestPlatformInfo(unittest.TestCase): | 71 class TestPlatformInfo(unittest.TestCase): |
70 def make_info(self, sys_module=None, platform_module=None, executive=None): | 72 def make_info(self, sys_module=None, platform_module=None, filesystem_module
=None, executive=None): |
71 return PlatformInfo(sys_module or fake_sys(), platform_module or fake_pl
atform(), executive or fake_executive()) | 73 return PlatformInfo(sys_module or fake_sys(), platform_module or fake_pl
atform(), filesystem_module or MockFileSystem(), executive or fake_executive()) |
72 | 74 |
73 def test_real_code(self): | 75 def test_real_code(self): |
74 # This test makes sure the real (unmocked) code actually works. | 76 # This test makes sure the real (unmocked) code actually works. |
75 info = PlatformInfo(sys, platform, Executive()) | 77 info = PlatformInfo(sys, platform, FileSystem(), Executive()) |
76 self.assertNotEquals(info.os_name, '') | 78 self.assertNotEquals(info.os_name, '') |
77 self.assertNotEquals(info.os_version, '') | 79 self.assertNotEquals(info.os_version, '') |
78 self.assertNotEquals(info.display_name(), '') | 80 self.assertNotEquals(info.display_name(), '') |
79 self.assertTrue(info.is_mac() or info.is_win() or info.is_linux() or inf
o.is_freebsd()) | 81 self.assertTrue(info.is_mac() or info.is_win() or info.is_linux() or inf
o.is_freebsd()) |
80 self.assertIsNotNone(info.terminal_width()) | 82 self.assertIsNotNone(info.terminal_width()) |
81 | 83 |
| 84 if info.is_linux(): |
| 85 self.assertIsNotNone(info.linux_distribution()) |
| 86 |
82 if info.is_mac(): | 87 if info.is_mac(): |
83 self.assertTrue(info.total_bytes_memory() > 0) | 88 self.assertTrue(info.total_bytes_memory() > 0) |
84 else: | 89 else: |
85 self.assertIsNone(info.total_bytes_memory()) | 90 self.assertIsNone(info.total_bytes_memory()) |
86 | 91 |
87 def test_os_name_and_wrappers(self): | 92 def test_os_name_and_wrappers(self): |
88 info = self.make_info(fake_sys('linux2')) | 93 info = self.make_info(fake_sys('linux2')) |
89 self.assertTrue(info.is_linux()) | 94 self.assertTrue(info.is_linux()) |
90 self.assertFalse(info.is_mac()) | 95 self.assertFalse(info.is_mac()) |
91 self.assertFalse(info.is_win()) | 96 self.assertFalse(info.is_win()) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 self.assertEqual(self.make_info(fake_sys('win32', tuple([6, 1, 7600]))).
os_version, '7sp0') | 152 self.assertEqual(self.make_info(fake_sys('win32', tuple([6, 1, 7600]))).
os_version, '7sp0') |
148 self.assertEqual(self.make_info(fake_sys('win32', tuple([6, 0, 1234]))).
os_version, 'vista') | 153 self.assertEqual(self.make_info(fake_sys('win32', tuple([6, 0, 1234]))).
os_version, 'vista') |
149 self.assertEqual(self.make_info(fake_sys('win32', tuple([5, 1, 1234]))).
os_version, 'xp') | 154 self.assertEqual(self.make_info(fake_sys('win32', tuple([5, 1, 1234]))).
os_version, 'xp') |
150 | 155 |
151 self.assertRaises(AssertionError, self.make_info, fake_sys('win32'), exe
cutive=fake_executive('5.0.1234')) | 156 self.assertRaises(AssertionError, self.make_info, fake_sys('win32'), exe
cutive=fake_executive('5.0.1234')) |
152 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('6.2.1234')).os_version, 'future') | 157 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('6.2.1234')).os_version, 'future') |
153 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('6.1.7600')).os_version, '7sp0') | 158 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('6.1.7600')).os_version, '7sp0') |
154 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('6.0.1234')).os_version, 'vista') | 159 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('6.0.1234')).os_version, 'vista') |
155 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('5.1.1234')).os_version, 'xp') | 160 self.assertEqual(self.make_info(fake_sys('cygwin'), executive=fake_execu
tive('5.1.1234')).os_version, 'xp') |
156 | 161 |
| 162 def _assert_file_implies_linux_distribution(self, file, distribution): |
| 163 info = self.make_info(sys_module=fake_sys('linux2'), filesystem_module=M
ockFileSystem({file: ''})) |
| 164 self.assertEqual(info.linux_distribution(), distribution) |
| 165 |
| 166 def test_linux_distro_detection(self): |
| 167 self._assert_file_implies_linux_distribution('/etc/arch-release', 'arch'
) |
| 168 self._assert_file_implies_linux_distribution('/etc/debian_version', 'deb
ian') |
| 169 self._assert_file_implies_linux_distribution('/etc/redhat-release', 'red
hat') |
| 170 self._assert_file_implies_linux_distribution('/etc/mock-release', 'unkno
wn') |
| 171 |
| 172 info = self.make_info(fake_sys('cygwin'), executive=fake_executive('6.1.
7600')) |
| 173 self.assertIsNone(info.linux_distribution()) |
| 174 |
157 def test_display_name(self): | 175 def test_display_name(self): |
158 info = self.make_info(fake_sys('darwin')) | 176 info = self.make_info(fake_sys('darwin')) |
159 self.assertNotEquals(info.display_name(), '') | 177 self.assertNotEquals(info.display_name(), '') |
160 | 178 |
161 info = self.make_info(fake_sys('win32', tuple([6, 1, 7600]))) | 179 info = self.make_info(fake_sys('win32', tuple([6, 1, 7600]))) |
162 self.assertNotEquals(info.display_name(), '') | 180 self.assertNotEquals(info.display_name(), '') |
163 | 181 |
164 info = self.make_info(fake_sys('linux2')) | 182 info = self.make_info(fake_sys('linux2')) |
165 self.assertNotEquals(info.display_name(), '') | 183 self.assertNotEquals(info.display_name(), '') |
166 | 184 |
167 info = self.make_info(fake_sys('freebsd9')) | 185 info = self.make_info(fake_sys('freebsd9')) |
168 self.assertNotEquals(info.display_name(), '') | 186 self.assertNotEquals(info.display_name(), '') |
169 | 187 |
170 def test_total_bytes_memory(self): | 188 def test_total_bytes_memory(self): |
171 info = self.make_info(fake_sys('darwin'), fake_platform('10.6.3'), fake_
executive('1234')) | 189 info = self.make_info(fake_sys('darwin'), fake_platform('10.6.3'), execu
tive=fake_executive('1234')) |
172 self.assertEqual(info.total_bytes_memory(), 1234) | 190 self.assertEqual(info.total_bytes_memory(), 1234) |
173 | 191 |
174 info = self.make_info(fake_sys('win32', tuple([6, 1, 7600]))) | 192 info = self.make_info(fake_sys('win32', tuple([6, 1, 7600]))) |
175 self.assertIsNone(info.total_bytes_memory()) | 193 self.assertIsNone(info.total_bytes_memory()) |
176 | 194 |
177 info = self.make_info(fake_sys('linux2')) | 195 info = self.make_info(fake_sys('linux2')) |
178 self.assertIsNone(info.total_bytes_memory()) | 196 self.assertIsNone(info.total_bytes_memory()) |
179 | 197 |
180 info = self.make_info(fake_sys('freebsd9')) | 198 info = self.make_info(fake_sys('freebsd9')) |
181 self.assertIsNone(info.total_bytes_memory()) | 199 self.assertIsNone(info.total_bytes_memory()) |
OLD | NEW |