mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Migrate cbor example to pytest framework
This commit is contained in:
parent
1f47466664
commit
57e2e7a27c
@ -1,44 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_Protocols')
|
||||
def test_examples_cbor(env, extra_data):
|
||||
|
||||
dut = env.get_dut('cbor', 'examples/protocols/cbor')
|
||||
dut.start_app()
|
||||
dut.expect(re.compile(r'example: encoded buffer size \d+'))
|
||||
dut.expect('example: convert CBOR to JSON')
|
||||
parsed_info = dut.expect(re.compile(r'\[\{"chip":"(\w+)","unicore":(\w+),"ip":\[(\d+),(\d+),(\d+),(\d+)\]\},'
|
||||
r'3.1400001049041748'
|
||||
r',"simple\(99\)","2019-07-10 09:00:00\+0000","undefined"\]'))
|
||||
dut.expect('example: decode CBOR manually')
|
||||
|
||||
dut.expect(re.compile(textwrap.dedent(r'''
|
||||
Array\[\s+
|
||||
Map{{\s+
|
||||
chip\s+
|
||||
{}\s+
|
||||
unicore\s+
|
||||
{}\s+
|
||||
ip\s+
|
||||
Array\[\s+
|
||||
{}\s+
|
||||
{}\s+
|
||||
{}\s+
|
||||
{}\s+
|
||||
\]\s+
|
||||
}}\s+
|
||||
3.14\s+
|
||||
simple\(99\)\s+
|
||||
2019-07-10 09:00:00\+0000\s+
|
||||
undefined\s+
|
||||
\]'''.format(*parsed_info)).replace('{', r'\{').replace('}', r'\}')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_cbor()
|
42
examples/protocols/cbor/pytest_cbor.py
Normal file
42
examples/protocols/cbor/pytest_cbor.py
Normal file
@ -0,0 +1,42 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.wifi
|
||||
def test_examples_cbor(dut: Dut) -> None:
|
||||
|
||||
dut.expect(r'example: encoded buffer size \d+')
|
||||
dut.expect('example: convert CBOR to JSON')
|
||||
parsed_info = dut.expect(r'\[\{"chip":"(\w+)","unicore":(\w+),"ip":\[(\d+),(\d+),(\d+),(\d+)\]\},'
|
||||
r'3.1400001049041748'
|
||||
r',"simple\(99\)","2019-07-10 09:00:00\+0000","undefined"\]')
|
||||
dut.expect('example: decode CBOR manually')
|
||||
|
||||
dut.expect(textwrap.dedent(r'''
|
||||
Array\[\s+
|
||||
Map{{\s+
|
||||
chip\s+
|
||||
{}\s+
|
||||
unicore\s+
|
||||
{}\s+
|
||||
ip\s+
|
||||
Array\[\s+
|
||||
{}\s+
|
||||
{}\s+
|
||||
{}\s+
|
||||
{}\s+
|
||||
\]\s+
|
||||
}}\s+
|
||||
3.14\s+
|
||||
simple\(99\)\s+
|
||||
2019-07-10 09:00:00\+0000\s+
|
||||
undefined\s+
|
||||
\]'''.format(parsed_info[1].decode(), parsed_info[2].decode(), parsed_info[3].decode(),
|
||||
parsed_info[4].decode(), parsed_info[5].decode(),parsed_info[6].decode())).replace('{', r'\{').replace('}', r'\}'))
|
Loading…
x
Reference in New Issue
Block a user