forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffx_emulator_unittests.py
executable file
·105 lines (95 loc) · 4 KB
/
ffx_emulator_unittests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env vpython3
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""File for testing ffx_emulator.py."""
import argparse
import unittest
import unittest.mock as mock
from ffx_emulator import FfxEmulator
class FfxEmulatorTest(unittest.TestCase):
"""Unittests for ffx_emulator.py"""
def test_use_fixed_node_name(self) -> None:
"""FfxEmulator should use a fixed node name."""
# Allowing the test case to access FfxEmulator._node_name directly.
# pylint: disable=protected-access
self.assertEqual(
FfxEmulator(
argparse.Namespace(
**{
'product': None,
'enable_graphics': False,
'hardware_gpu': False,
'logs_dir': '.',
'with_network': False,
'everlasting': True,
'device_spec': ''
}))._node_name, 'fuchsia-everlasting-emulator')
def test_use_random_node_name(self) -> None:
"""FfxEmulator should not use a fixed node name."""
# Allowing the test case to access FfxEmulator._node_name directly.
# pylint: disable=protected-access
self.assertNotEqual(
FfxEmulator(
argparse.Namespace(
**{
'product': None,
'enable_graphics': False,
'hardware_gpu': False,
'logs_dir': '.',
'with_network': False,
'everlasting': False,
'device_spec': ''
}))._node_name, 'fuchsia-everlasting-emulator')
@mock.patch('ffx_emulator.run_ffx_command')
def test_use_none_device_spec(self, mock_ffx) -> None:
"""FfxEmulator should use the default device spec if spec is None."""
FfxEmulator(
argparse.Namespace(
**{
'product': None,
'enable_graphics': False,
'hardware_gpu': False,
'logs_dir': '.',
'with_network': False,
'everlasting': False,
'device_spec': None
})).__enter__()
self.assertIn(' '.join(['--net', 'user']),
' '.join(mock_ffx.call_args.kwargs['cmd']))
self.assertNotIn('--device', mock_ffx.call_args.kwargs['cmd'])
@mock.patch('ffx_emulator.run_ffx_command')
def test_use_empty_device_spec(self, mock_ffx) -> None:
"""FfxEmulator should use the default device spec if spec is empty."""
FfxEmulator(
argparse.Namespace(
**{
'product': None,
'enable_graphics': False,
'hardware_gpu': False,
'logs_dir': '.',
'with_network': False,
'everlasting': False,
'device_spec': ''
})).__enter__()
self.assertIn(' '.join(['--net', 'user']),
' '.join(mock_ffx.call_args.kwargs['cmd']))
self.assertNotIn('--device', mock_ffx.call_args.kwargs['cmd'])
@mock.patch('ffx_emulator.run_ffx_command')
def test_use_large_device_spec(self, mock_ffx) -> None:
"""FfxEmulator should use large device spec."""
FfxEmulator(
argparse.Namespace(
**{
'product': None,
'enable_graphics': False,
'hardware_gpu': False,
'logs_dir': '.',
'with_network': False,
'everlasting': False,
'device_spec': 'large'
})).__enter__()
self.assertIn(' '.join(['--device', 'large']),
' '.join(mock_ffx.call_args.kwargs['cmd']))
if __name__ == '__main__':
unittest.main()