def test_setup(mock_micropy_path): """Tests MicroPy Initial Setup""" expect_mp_dir = mock_micropy_path expect_stubs_dir = mock_micropy_path / "stubs" mp = main.MicroPy() assert expect_mp_dir.exists() assert expect_stubs_dir.exists() # Test after inital setup mp_ = main.MicroPy() assert len(mp_.stubs) == len(mp.stubs)
def test_setup(mock_micropy_path): """Tests MicroPy Initial Setup""" expect_mp_dir = mock_micropy_path expect_stubs_dir = mock_micropy_path / 'stubs' mp = main.MicroPy() print("MP FILES:", mp.FILES) print("MP Content:", list(mp.FILES.iterdir())) assert expect_mp_dir.exists() assert expect_stubs_dir.exists() # Test after inital setup mp_ = main.MicroPy() assert len(mp_.STUBS) == len(mp.STUBS)
def test_create_stub(mock_micropy, mocker, shared_datadir, tmp_path): """should create and add stubs""" mock_micropy.STUBS.add((shared_datadir / 'fware_test_stub')) tmp_stub_path = tmp_path / 'createtest' tmp_stub_path.mkdir() copytree(str(shared_datadir / 'stubber_test_stub'), str(tmp_stub_path / 'stubber_test_stub')) mock_pyb = mocker.patch("micropy.main.utils.PyboardWrapper") mock_pyb.return_value.copy_dir.return_value = Path(str(tmp_stub_path)) mock_pyb.side_effect = [ SystemExit, mock_pyb.return_value, mock_pyb.return_value, mock_pyb.return_value ] mp = main.MicroPy() mocker.spy(mp.STUBS, 'add') stub = mp.create_stubs("/dev/PORT") assert stub is None mock_pyb.return_value.run.side_effect = [Exception, mocker.ANY, mocker.ANY] stub = mp.create_stubs("/dev/PORT") assert stub is None stub = mp.create_stubs("/dev/PORT") mp.STUBS.add.assert_any_call((tmp_stub_path / 'esp32-1.11.0')) rmtree((tmp_stub_path / 'esp32-1.11.0')) assert isinstance(stub, stubs.DeviceStub) # Test outpath with firmware mod_path = tmp_stub_path / 'stubber_test_stub' / 'modules.json' mod_data = json.load(mod_path.open()) mod_data['firmware']['name'] = 'micropython' json.dump(mod_data, mod_path.open('w+')) stub = mp.create_stubs("/dev/PORT") mp.STUBS.add.assert_any_call((tmp_stub_path / 'esp32-micropython-1.11.0'))