I have some tests and run flake8 in https://github.com/jedie/micropython-sonoff-webswitch
This is also the first project used github actions as CI.
But the existing tests runs only with CPython.
Somebody tried to run tests with micropython using the Unix port in a CI pipeline?
test a micropython project?
Re: test a micropython project?
Maybe one way is to implement MicroPython-specific modules as mocks ? I started with this a little bit: https://github.com/jedie/micropython-so ... 8e569f8398
But maybe there already exists a full features mock project???
But maybe there already exists a full features mock project???
Re: test a micropython project?
The run-tests which comes with micropython itself is usable by CI builds (it gets used for all travis build for instance).
'Standard' unit tests for truly platform-indpendent code can be ran with CPython, for more micropython-specific code you could use unittest.py from the micropython-lib project and then run it either on the unix port or on an emulated or real target.
Irregardless of which method you use you can use mocks, but having to write a lot of those without having something like unittest.mock is tedious so whenever possible I prefer writing logic which can be tested easily without mocks, or else just run it on the target platform.
I don't think there's a working implementation of a mocking framework yet, but with functionality like __getattr__ etc being added to the core this should become possible.
'Standard' unit tests for truly platform-indpendent code can be ran with CPython, for more micropython-specific code you could use unittest.py from the micropython-lib project and then run it either on the unix port or on an emulated or real target.
Irregardless of which method you use you can use mocks, but having to write a lot of those without having something like unittest.mock is tedious so whenever possible I prefer writing logic which can be tested easily without mocks, or else just run it on the target platform.
I don't think there's a working implementation of a mocking framework yet, but with functionality like __getattr__ etc being added to the core this should become possible.
Re: test a micropython project?
I now implement "integration" tests using asynctest and test the full uasyncio.start_server() stack
Tests can look like this:
See: https://github.com/jedie/micropython-so ... 50d6991df6
I implement only mocks that currently been used, stuff like e.g.: gc.mem_free(), machine.unique_id()
Think it makes sence to split all this from the project and create a "mpy-test" project... But unfortunately the day only has 24 hours.
Tests can look like this:
Code: Select all
async def test_non_well_form_request(self):
response, server_message = await self.get_request(
request_line=b"GET-totaly-bullshit-HTTP/1.1"
)
assert response == 'HTTP/1.0 303 Moved\r\nLocation: /main/menu/\r\n\r\n'
assert server_message == 'not enough values to unpack (expected 3, got 1)'
async def test_get_main_menu(self):
response, server_message = await self.get_request(request_line=b"GET /main/menu/ HTTP/1.1")
self.assert_response_parts(
response,
parts=(
'HTTP/1.0 200 OK',
'<html>',
'<title>network name-04030201 - OFF</title>',
'<p>Power switch state: <strong>OFF</strong></p>',
'<p>Web server started...</p>',
'RAM total: 1.95 KB, used: 0.98 KB, free: 0.98 KB<br>',
'Server local time: 2000-01-01 00:00:00',
'</html>'
)
)
assert 'Web server started...' == server_message
I implement only mocks that currently been used, stuff like e.g.: gc.mem_free(), machine.unique_id()
Think it makes sence to split all this from the project and create a "mpy-test" project... But unfortunately the day only has 24 hours.