Lines Matching refs:self
38 def setUp(self): argument
41 self.args = mock.MagicMock()
42 self.args.flavor = ""
43 self.args.local_image = None
44 self.args.local_kernel_image = None
45 self.args.local_system_image = None
46 self.args.local_vendor_boot_image = None
47 self.args.config_file = ""
48 self.args.build_target = "fake_build_target"
49 self.args.adb_port = None
50 self.args.launch_args = None
51 self.Patch(list_instances, "ChooseOneRemoteInstance", return_value=mock.MagicMock())
52 self.Patch(list_instances, "GetInstancesFromInstanceNames", return_value=mock.MagicMock())
55 self.mock_config = mock.MagicMock()
56 self.mock_config.launch_args = None
57 self.Patch(config, 'GetAcloudConfig', return_value=self.mock_config)
59 self.AvdSpec = avd_spec.AVDSpec(self.args)
62 def testProcessLocalImageArgs(self): argument
64 self.Patch(glob, "glob", return_value=["fake.img"])
67 self.Patch(os.path, "exists",
70 self.Patch(os.path, "isdir",
72 self.Patch(os.path, "isfile",
76 self.args.local_image = "/path/cf_x86_phone-img-eng.user.zip"
77 self.AvdSpec._avd_type = constants.TYPE_CF
78 self.AvdSpec._instance_type = constants.INSTANCE_TYPE_REMOTE
79 self.AvdSpec._ProcessLocalImageArgs(self.args)
80 self.assertEqual(self.AvdSpec._local_image_artifact,
84 self.Patch(utils, "GetBuildEnvironmentVariable",
86 self.args.local_image = "/path-to-image-dir"
87 self.AvdSpec._avd_type = constants.TYPE_CF
88 self.AvdSpec._instance_type = constants.INSTANCE_TYPE_REMOTE
89 self.AvdSpec._ProcessLocalImageArgs(self.args)
90 self.assertEqual(self.AvdSpec._local_image_dir, expected_image_dir)
93 self.args.local_image = constants.FIND_IN_BUILD_ENV
94 self.Patch(utils, "GetBuildEnvironmentVariable",
96 self.AvdSpec._ProcessLocalImageArgs(self.args)
97 self.assertEqual(self.AvdSpec._local_image_dir, "test_environ")
98 self.assertEqual(self.AvdSpec.local_image_artifact, expected_image_artifact)
101 self.Patch(utils, "GetBuildEnvironmentVariable",
103 self.args.local_image = "/path-to-image-dir"
104 self.AvdSpec._avd_type = constants.TYPE_GF
105 self.AvdSpec._instance_type = constants.INSTANCE_TYPE_LOCAL
106 self.AvdSpec._ProcessLocalImageArgs(self.args)
107 self.assertEqual(self.AvdSpec._local_image_dir, expected_image_dir)
109 def testProcessLocalMixedImageArgs(self): argument
113 self.Patch(os.path, "exists",
116 self.Patch(os.path, "isdir",
118 self.Patch(os.path, "isfile",
122 self.args.local_kernel_image = expected_image_dir
123 self.args.local_system_image = expected_image_dir
124 self.args.local_system_dlkm_image = expected_image_dir
125 self.args.local_vendor_image = expected_image_dir
126 self.AvdSpec._ProcessImageArgs(self.args)
127 self.assertEqual(self.AvdSpec.local_kernel_image, expected_image_dir)
128 self.assertEqual(self.AvdSpec.local_system_image, expected_image_dir)
129 self.assertEqual(self.AvdSpec.local_system_dlkm_image, expected_image_dir)
130 self.assertEqual(self.AvdSpec.local_vendor_image, expected_image_dir)
133 self.args.local_kernel_image = expected_image_file
134 self.args.local_system_image = expected_image_file
135 self.args.local_system_dlkm_image = expected_image_file
136 self.args.local_vendor_boot_image = expected_image_file
137 self.AvdSpec._ProcessImageArgs(self.args)
138 self.assertEqual(self.AvdSpec.local_kernel_image, expected_image_file)
139 self.assertEqual(self.AvdSpec.local_system_image, expected_image_file)
140 self.assertEqual(self.AvdSpec.local_system_dlkm_image, expected_image_file)
141 self.assertEqual(self.AvdSpec.local_vendor_boot_image, expected_image_file)
144 self.args.local_kernel_image = constants.FIND_IN_BUILD_ENV
145 self.args.local_system_image = constants.FIND_IN_BUILD_ENV
146 self.args.local_system_dlkm_image = constants.FIND_IN_BUILD_ENV
147 self.args.local_vendor_image = constants.FIND_IN_BUILD_ENV
151 self.AvdSpec._ProcessImageArgs(self.args)
152 self.assertEqual(self.AvdSpec.local_kernel_image, expected_image_dir)
153 self.assertEqual(self.AvdSpec.local_system_image, expected_image_dir)
154 self.assertEqual(self.AvdSpec.local_system_dlkm_image, expected_image_dir)
155 self.assertEqual(self.AvdSpec.local_vendor_image, expected_image_dir)
157 def testProcessAutoconnect(self): argument
159 self.AvdSpec._autoconnect = False
160 self.AvdSpec._ProcessAutoconnect()
161 self.assertEqual(self.AvdSpec._autoconnect, False)
163 self.AvdSpec._avd_type = constants.TYPE_CF
164 self.AvdSpec._autoconnect = "webrtc"
165 self.AvdSpec._ProcessAutoconnect()
166 self.assertEqual(self.AvdSpec._autoconnect, "webrtc")
168 self.AvdSpec._autoconnect = "vnc"
169 self.AvdSpec._ProcessAutoconnect()
170 self.assertEqual(self.AvdSpec._autoconnect, "vnc")
172 self.AvdSpec._avd_type = constants.TYPE_GF
173 self.AvdSpec._autoconnect = "webrtc"
174 self.AvdSpec._ProcessAutoconnect()
175 self.assertEqual(self.AvdSpec._autoconnect, "vnc")
177 def testProcessImageArgs(self): argument
179 self.Patch(glob, "glob", return_value=["fake.img"])
181 self.AvdSpec._ProcessImageArgs(self.args)
182 self.assertEqual(self.AvdSpec._image_source, constants.IMAGE_SRC_REMOTE)
183 self.assertEqual(self.AvdSpec._local_image_dir, None)
184 self.assertEqual(self.AvdSpec.local_kernel_image, None)
185 self.assertEqual(self.AvdSpec.local_system_image, None)
188 self.Patch(os.path, "isfile", return_value=True)
189 self.args.local_image = "/test_path/cf_x86_phone-img-eng.user.zip"
190 self.AvdSpec._avd_type = constants.TYPE_CF
191 self.AvdSpec._instance_type = constants.INSTANCE_TYPE_REMOTE
192 self.AvdSpec._ProcessImageArgs(self.args)
193 self.assertEqual(self.AvdSpec._image_source, constants.IMAGE_SRC_LOCAL)
194 self.assertEqual(self.AvdSpec._local_image_artifact,
198 self.Patch(os.path, "isfile", return_value=False)
199 self.Patch(os.path, "exists", return_value=True)
200 self.args.local_image = "/test_path_to_dir/"
201 self.AvdSpec._avd_type = constants.TYPE_GCE
202 self.AvdSpec._ProcessImageArgs(self.args)
203 self.assertEqual(self.AvdSpec._image_source, constants.IMAGE_SRC_LOCAL)
204 self.assertEqual(self.AvdSpec._local_image_artifact,
208 def testGetBranchFromRepo(self, mock_gitremote): argument
218 self.Patch(subprocess, "Popen", return_value=fake_subprocess)
221 self.assertEqual(self.AvdSpec._GetBranchFromRepo(), "aosp-fake_branch")
227 self.Patch(subprocess, "Popen", return_value=fake_subprocess)
228 self.assertEqual(self.AvdSpec._GetBranchFromRepo(), "git_fake_branch")
233 self.Patch(subprocess, "Popen", return_value=fake_subprocess)
234 self.assertEqual(self.AvdSpec._GetBranchFromRepo(), "aosp-master")
236 def testGetBuildBranch(self): argument
243 self.Patch(android_build_client, "AndroidBuildClient",
245 self.Patch(auth, "CreateCredentials", return_value=mock.MagicMock())
246 self.Patch(build_client, "GetBranch", return_value=expected_branch)
247 self.assertEqual(self.AvdSpec._GetBuildBranch(build_id, build_target),
250 self.Patch(self.AvdSpec, "_GetBranchFromRepo", return_value="repo_branch")
254 self.assertEqual(self.AvdSpec._GetBuildBranch(build_id, build_target),
258 def testGetBuildTarget(self): argument
261 self.AvdSpec._flavor = constants.FLAVOR_IOT
262 self.args.avd_type = constants.TYPE_GCE
263 self.assertEqual(
264 self.AvdSpec._GetBuildTarget(self.args, branch),
268 self.AvdSpec._flavor = constants.FLAVOR_PHONE
269 self.args.avd_type = constants.TYPE_CF
270 self.assertEqual(
271 self.AvdSpec._GetBuildTarget(self.args, branch),
275 self.AvdSpec._flavor = constants.FLAVOR_PHONE
276 self.args.avd_type = constants.TYPE_CF
277 self.assertEqual(
278 self.AvdSpec._GetBuildTarget(self.args, branch),
282 self.AvdSpec._flavor = constants.FLAVOR_PHONE
283 self.args.avd_type = constants.TYPE_CF
284 self.assertEqual(
285 self.AvdSpec._GetBuildTarget(self.args, branch),
289 def testProcessHWPropertyWithInvalidArgs(self): argument
295 with self.assertRaises(errors.InvalidHWPropertyError):
296 self.AvdSpec._ProcessHWPropertyArgs(args)
301 with self.assertRaises(errors.InvalidHWPropertyError):
302 self.AvdSpec._ProcessHWPropertyArgs(args)
307 with self.assertRaises(errors.InvalidHWPropertyError):
308 self.AvdSpec._ProcessHWPropertyArgs(args)
313 with self.assertRaises(errors.InvalidHWPropertyError):
314 self.AvdSpec._ProcessHWPropertyArgs(args)
318 def testCheckCFBuildTarget(self, print_warning): argument
321 self.Patch(utils, "GetBuildEnvironmentVariable",
323 self.AvdSpec._CheckCFBuildTarget(constants.INSTANCE_TYPE_REMOTE)
324 self.AvdSpec._CheckCFBuildTarget(constants.INSTANCE_TYPE_LOCAL)
326 self.Patch(utils, "GetBuildEnvironmentVariable",
328 self.AvdSpec._CheckCFBuildTarget(constants.INSTANCE_TYPE_HOST)
330 self.Patch(utils, "GetBuildEnvironmentVariable",
332 self.AvdSpec._CheckCFBuildTarget(constants.INSTANCE_TYPE_REMOTE)
337 def testParseHWPropertyStr(self): argument
342 result_dict = self.AvdSpec._ParseHWPropertyStr(args_str)
343 self.assertTrue(expected_dict == result_dict)
348 result_dict = self.AvdSpec._ParseHWPropertyStr(args_str)
349 self.assertTrue(expected_dict == result_dict)
351 def testGetFlavorFromBuildTargetString(self): argument
354 self.assertEqual(self.AvdSpec._GetFlavorFromString(img_path),
358 self.assertEqual(self.AvdSpec._GetFlavorFromString(
363 self.assertEqual(self.AvdSpec._GetFlavorFromString(img_path),
367 def testProcessRemoteBuildArgs(self): argument
369 self.args.branch = "git_master"
370 self.args.build_id = "1234"
371 self.args.launch_args = None
374 self.args.build_target = "aosp_gce_x86_phone-userdebug"
375 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
376 self.assertTrue(self.AvdSpec.avd_type == "gce")
379 self.args.build_target = "gce_x86_phone-userdebug"
380 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
381 self.assertTrue(self.AvdSpec.avd_type == "gce")
384 self.args.build_target = "aosp_cf_x86_64_phone-userdebug"
385 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
386 self.assertTrue(self.AvdSpec.avd_type == "cuttlefish")
389 self.args.build_target = "cf_x86_phone-userdebug"
390 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
391 self.assertTrue(self.AvdSpec.avd_type == "cuttlefish")
394 self.args.build_target = "sdk_phone_armv7-sdk"
395 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
396 self.assertTrue(self.AvdSpec.avd_type == "goldfish")
399 self.args.build_target = "aosp_sdk_phone_armv7-sdk"
400 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
401 self.assertTrue(self.AvdSpec.avd_type == "goldfish")
404 self.args.system_branch = "system_branch"
405 self.args.system_build_target = "system_build_target"
406 self.args.system_build_id = "system_build_id"
407 self.args.ota_branch = "ota_branch"
408 self.args.ota_build_target = "ota_build_target"
409 self.args.ota_build_id = "ota_build_id"
410 self.args.kernel_branch = "kernel_branch"
411 self.args.kernel_build_target = "kernel_build_target"
412 self.args.kernel_build_id = "kernel_build_id"
413 self.args.boot_branch = "boot_branch"
414 self.args.boot_build_target = "boot_build_target"
415 self.args.boot_build_id = "boot_build_id"
416 self.args.boot_artifact = "boot_artifact"
417 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
418 self.assertEqual(
422 self.AvdSpec.system_build_info)
423 self.assertEqual(
427 self.AvdSpec.kernel_build_info)
428 self.assertEqual(
433 self.AvdSpec.boot_build_info)
434 self.assertEqual(
438 self.AvdSpec.ota_build_info)
441 self.args.build_target = "mini_emulator_arm64-userdebug"
442 self.args.avd_type = "cuttlefish"
444 self.AvdSpec = avd_spec.AVDSpec(self.args)
445 self.AvdSpec._ProcessRemoteBuildArgs(self.args)
446 self.assertTrue(self.AvdSpec.avd_type == "cuttlefish")
448 def testEscapeAnsi(self): argument
452 self.assertEqual(avd_spec.EscapeAnsi(test_string), expected_result)
454 def testGetGceLocalImagePath(self): argument
456 self.Patch(os.path, "isfile", return_value=True)
459 self.Patch(os.path, "exists", return_value=True)
460 self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path),
465 self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path),
469 self.Patch(os.path, "isfile", return_value=False)
470 self.Patch(os.path, "exists", return_value=True)
473 self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path),
478 self.Patch(os.path, "exists", side_effect=[False, True])
479 self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path),
483 self.Patch(os.path, "exists", side_effect=[False, False])
484 self.assertRaises(errors.ImgDoesNotExist,
485 self.AvdSpec._GetGceLocalImagePath, fake_image_path)
487 def testProcessMiscArgs(self): argument
489 self.args.remote_host = None
490 self.args.local_instance = None
491 self.AvdSpec._ProcessMiscArgs(self.args)
492 self.assertEqual(self.AvdSpec._instance_type, constants.INSTANCE_TYPE_REMOTE)
494 self.args.remote_host = None
495 self.args.local_instance = 0
496 self.AvdSpec._ProcessMiscArgs(self.args)
497 self.assertEqual(self.AvdSpec._instance_type, constants.INSTANCE_TYPE_LOCAL)
499 self.args.remote_host = "1.1.1.1"
500 self.args.local_instance = None
501 self.AvdSpec._ProcessMiscArgs(self.args)
502 self.assertEqual(self.AvdSpec._instance_type, constants.INSTANCE_TYPE_HOST)
504 self.args.remote_host = "1.1.1.1"
505 self.args.local_instance = 1
506 self.AvdSpec._ProcessMiscArgs(self.args)
507 self.assertEqual(self.AvdSpec._instance_type, constants.INSTANCE_TYPE_HOST)
509 self.args.oxygen = True
510 self.AvdSpec._ProcessMiscArgs(self.args)
511 self.assertTrue(self.AvdSpec._oxygen)
514 self.args.autoconnect = False
515 self.AvdSpec._ProcessMiscArgs(self.args)
516 self.assertEqual(self.AvdSpec.autoconnect, False)
517 self.assertEqual(self.AvdSpec.connect_adb, False)
518 self.assertEqual(self.AvdSpec.connect_vnc, False)
519 self.assertEqual(self.AvdSpec.connect_webrtc, False)
521 self.args.autoconnect = constants.INS_KEY_VNC
522 self.AvdSpec._ProcessMiscArgs(self.args)
523 self.assertEqual(self.AvdSpec.autoconnect, True)
524 self.assertEqual(self.AvdSpec.connect_adb, True)
525 self.assertEqual(self.AvdSpec.connect_vnc, True)
526 self.assertEqual(self.AvdSpec.connect_webrtc, False)
528 self.args.autoconnect = constants.INS_KEY_ADB
529 self.AvdSpec._ProcessMiscArgs(self.args)
530 self.assertEqual(self.AvdSpec.autoconnect, True)
531 self.assertEqual(self.AvdSpec.connect_adb, True)
532 self.assertEqual(self.AvdSpec.connect_vnc, False)
533 self.assertEqual(self.AvdSpec.connect_webrtc, False)
535 self.args.autoconnect = constants.INS_KEY_WEBRTC
536 self.AvdSpec._ProcessMiscArgs(self.args)
537 self.assertEqual(self.AvdSpec.autoconnect, True)
538 self.assertEqual(self.AvdSpec.connect_adb, True)
539 self.assertEqual(self.AvdSpec.connect_vnc, False)
540 self.assertEqual(self.AvdSpec.connect_webrtc, True)
543 self.args.stable_host_image_name = "fake_host_image"
544 self.AvdSpec._ProcessMiscArgs(self.args)
545 self.assertEqual(self.AvdSpec.stable_host_image_name, "fake_host_image")
548 self.mock_config.betty_image = 'from-config'
550 self.args.cheeps_betty_image = 'from-cmdline'
551 self.AvdSpec._ProcessMiscArgs(self.args)
552 self.assertEqual(self.AvdSpec.cheeps_betty_image, 'from-cmdline')
554 self.args.cheeps_betty_image = None
555 self.AvdSpec._ProcessMiscArgs(self.args)
556 self.assertEqual(self.AvdSpec.cheeps_betty_image, 'from-config')
559 self.args.cheeps_features = ['a', 'b', 'c']
560 self.AvdSpec._ProcessMiscArgs(self.args)
561 self.assertEqual(self.args.cheeps_features, ['a', 'b', 'c'])
564 self.mock_config.connect_hostname = True
565 self.AvdSpec._ProcessMiscArgs(self.args)
566 self.assertTrue(self.AvdSpec.connect_hostname)
567 self.args.connect_hostname = True
568 self.mock_config.connect_hostname = False
569 self.assertTrue(self.AvdSpec.connect_hostname)
572 self.args.fetch_cvd_build_id = None
573 self.AvdSpec._ProcessMiscArgs(self.args)
574 self.assertEqual(self.AvdSpec.fetch_cvd_version, "LKGB")
576 self.args.fetch_cvd_build_id = "23456"
577 self.AvdSpec._ProcessMiscArgs(self.args)
578 self.assertEqual(self.AvdSpec.fetch_cvd_version, "23456")