def __init__(self, *args, support_file=None, git=None, **kwargs): super().__init__(*args, **kwargs) # If a test sets this property, the tool verification step will # fail. self._missing_tool = None # Mock the external services self.git = git self.cookiecutter = mock.MagicMock() self.subprocess = mock.MagicMock() self.support_file = support_file self.input = DummyConsole()
def mock_sdk(tmp_path): command = MagicMock() command.home_path = tmp_path command.subprocess = MagicMock() command.input = DummyConsole() # Mock an empty environment command.os.environ = {} # Set a JAVA_HOME command.java_home_path = Path('/path/to/jdk') sdk = AndroidSDK(command, root_path=tmp_path / 'sdk') return sdk
def test_select_option(): # Return '3' when prompted console = DummyConsole("3") options = { "first": "The first option", "second": "The second option", "third": "The third option", "fourth": "The fourth option", } result = select_option(options, input=console) # Input is requested once assert console.prompts == ["> "] # Alphabetically, option 3 will be "the second option" assert result == "second"
def test_select_option(): # Return '3' when prompted console = DummyConsole('3') options = { 'first': 'The first option', 'second': 'The second option', 'third': 'The third option', 'fourth': 'The fourth option', } result = select_option(options, input=console) # Input is requested once assert console.prompts == ['> '] # Alphabetically, option 3 will be "the second option" assert result == 'second'
def test_select_option_list(): "If select_option is given a list of tuples, they're presented as provided" # Return '3' when prompted console = DummyConsole('3') options = [ ('first', 'The first option'), ('second', 'The second option'), ('third', 'The third option'), ('fourth', 'The fourth option'), ] result = select_option(options, input=console) # Input is requested once assert console.prompts == ['> '] # The third option is the third option :-) assert result == 'third'
def test_select_option_list(): """If select_option is given a list of tuples, they're presented as provided.""" # Return '3' when prompted console = DummyConsole("3") options = [ ("first", "The first option"), ("second", "The second option"), ("third", "The third option"), ("fourth", "The fourth option"), ] result = select_option(options, input=console) # Input is requested once assert console.prompts == ["> "] # The third option is the third option :-) assert result == "third"
def test_select_option_bad_input(): # In order, return: # blank # 'asdf' # '10' # '3' console = DummyConsole("", "asdf", "10", "3") options = { "first": "The first option", "second": "The second option", "third": "The third option", "fourth": "The fourth option", } result = select_option(options, input=console) # Input is requested five times; first four cause errors. assert console.prompts == ["> "] * 4 # Alphabetically, option 3 will be "the second option" assert result == "second"
def mock_sdk(tmp_path): command = MagicMock() command.home_path = tmp_path command.subprocess = MagicMock() command.input = DummyConsole() command.logger = Log(verbosity=1) # For default test purposes, assume we're on macOS x86_64 command.host_os = "Darwin" command.host_arch = "x86_64" # Mock an empty environment command.os.environ = {} # Set up a JDK jdk = MagicMock() jdk.java_home = Path("/path/to/jdk") sdk = AndroidSDK(command, jdk=jdk, root_path=tmp_path / "sdk") return sdk
def test_select_option_bad_input(): # In order, return: # blank # 'asdf' # '10' # '3' console = DummyConsole('', 'asdf', '10', '3') options = { 'first': 'The first option', 'second': 'The second option', 'third': 'The third option', 'fourth': 'The fourth option', } result = select_option(options, input=console) # Input is requested five times; first four cause errors. assert console.prompts == ['> '] * 4 # Alphabetically, option 3 will be "the second option" assert result == 'second'
def mock_sdk(tmp_path): command = MagicMock() command.logger = Log() command.input = DummyConsole() sdk = AndroidSDK(command, jdk=MagicMock(), root_path=tmp_path) sdk.devices = MagicMock( return_value={ "041234567892009a": { "name": "Unknown device (not authorized for development)", "authorized": False, }, "KABCDABCDA1513": { "name": "Kogan Agora 9", "authorized": True, }, "emulator-5554": { "name": "Android SDK built for x86", "authorized": True, }, }) sdk.emulators = MagicMock(return_value=[ "runningEmulator", "idleEmulator", ]) # Set up an ADB for each device. def mock_adb(device_id): adb = MagicMock() if device_id == "emulator-5554": adb.avd_name.return_value = "runningEmulator" else: adb.avd_name.return_value = None return adb sdk.adb = mock_adb return sdk
def mock_sdk(tmp_path): command = MagicMock() command.input = DummyConsole() sdk = AndroidSDK(command, root_path=tmp_path) sdk.devices = MagicMock( return_value={ '041234567892009a': { 'name': 'Unknown device (not authorized for development)', 'authorized': False, }, 'KABCDABCDA1513': { 'name': 'Kogan_Agora_9', 'authorized': True, }, 'emulator-5554': { 'name': 'generic_x86', 'authorized': True, }, }) sdk.emulators = MagicMock(return_value=[ 'runningEmulator', 'idleEmulator', ]) # Set up an ADB for each device. def mock_adb(device_id): adb = MagicMock() if device_id == 'emulator-5554': adb.avd_name.return_value = 'runningEmulator' else: adb.avd_name.return_value = None return adb sdk.adb = mock_adb return sdk
def __init__(self, base_path, **kwargs): super().__init__(base_path=base_path, **kwargs) self.input = DummyConsole()
def __init__(self, *args, **kwargs): super().__init__(*args, apps=[], **kwargs) self.actions = [] self.input = DummyConsole()