mirror of
https://github.com/micropython/micropython.git
synced 2025-09-07 10:20:52 +02:00
Some checks are pending
JavaScript code lint and formatting with Biome / eslint (push) Waiting to run
Check code formatting / code-formatting (push) Waiting to run
Check spelling with codespell / codespell (push) Waiting to run
Build docs / build (push) Waiting to run
Check examples / embedding (push) Waiting to run
Package mpremote / build (push) Waiting to run
.mpy file format and tools / test (push) Waiting to run
Build ports metadata / build (push) Waiting to run
cc3200 port / build (push) Waiting to run
esp32 port / build_idf (esp32_build_cmod_spiram_s2) (push) Waiting to run
esp32 port / build_idf (esp32_build_s3_c3) (push) Waiting to run
esp8266 port / build (push) Waiting to run
mimxrt port / build (push) Waiting to run
nrf port / build (push) Waiting to run
powerpc port / build (push) Waiting to run
qemu port / build_and_test_arm (push) Waiting to run
qemu port / build_and_test_rv32 (push) Waiting to run
renesas-ra port / build_renesas_ra_board (push) Waiting to run
rp2 port / build (push) Waiting to run
samd port / build (push) Waiting to run
stm32 port / build_stm32 (stm32_misc_build) (push) Waiting to run
stm32 port / build_stm32 (stm32_nucleo_build) (push) Waiting to run
stm32 port / build_stm32 (stm32_pyb_build) (push) Waiting to run
unix port / minimal (push) Waiting to run
unix port / reproducible (push) Waiting to run
unix port / standard (push) Waiting to run
unix port / standard_v2 (push) Waiting to run
unix port / coverage (push) Waiting to run
unix port / coverage_32bit (push) Waiting to run
unix port / nanbox (push) Waiting to run
unix port / float (push) Waiting to run
unix port / stackless_clang (push) Waiting to run
unix port / float_clang (push) Waiting to run
unix port / settrace (push) Waiting to run
unix port / settrace_stackless (push) Waiting to run
unix port / macos (push) Waiting to run
unix port / qemu_mips (push) Waiting to run
unix port / qemu_arm (push) Waiting to run
unix port / qemu_riscv64 (push) Waiting to run
webassembly port / build (push) Waiting to run
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-mingw (i686, mingw32, dev) (push) Waiting to run
windows port / build-mingw (i686, mingw32, standard) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, dev) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, standard) (push) Waiting to run
windows port / cross-build-on-linux (push) Waiting to run
zephyr port / build (push) Waiting to run
Python code lint and formatting with ruff / ruff (push) Waiting to run
Found by codespell. Signed-off-by: Christian Clauss <cclauss@me.com>
68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
# Test the esp32 NVS class - access to esp-idf's Non-Volatile-Storage
|
|
|
|
from esp32 import NVS
|
|
|
|
nvs = NVS("mp-test")
|
|
|
|
# test setting and getting an integer kv
|
|
nvs.set_i32("key1", 1234)
|
|
print(nvs.get_i32("key1"))
|
|
nvs.set_i32("key2", -503)
|
|
print(nvs.get_i32("key2"))
|
|
print(nvs.get_i32("key1"))
|
|
|
|
# test setting and getting a blob kv using a bytearray
|
|
blob1 = "testing a string as a blob"
|
|
nvs.set_blob("blob1", blob1)
|
|
buf1 = bytearray(len(blob1))
|
|
len1 = nvs.get_blob("blob1", buf1)
|
|
print(buf1)
|
|
print(len(blob1), len1)
|
|
|
|
# test setting and getting a blob kv using a string
|
|
blob2 = b"testing a bytearray"
|
|
nvs.set_blob("blob2", blob2)
|
|
buf2 = bytearray(len(blob2))
|
|
len2 = nvs.get_blob("blob2", buf2)
|
|
print(buf2)
|
|
print(len(blob2), len2)
|
|
|
|
# test raising of error exceptions
|
|
nvs.erase_key("key1")
|
|
try:
|
|
nvs.erase_key("key1") # not found
|
|
except OSError as e:
|
|
print(e)
|
|
try:
|
|
nvs.get_i32("key1") # not found
|
|
except OSError as e:
|
|
print(e)
|
|
try:
|
|
nvs.get_i32("blob1") # not found (blob1 exists but diff type)
|
|
except OSError as e:
|
|
print(e)
|
|
try:
|
|
buf3 = bytearray(10)
|
|
nvs.get_blob("blob1", buf3) # invalid length (too short)
|
|
except OSError as e:
|
|
print(e)
|
|
|
|
nvs.commit() # we're not verifying that this does anything, just doesn't error
|
|
|
|
# test using a second namespace and that it doesn't interfere with first
|
|
nvs2 = NVS("mp-test2")
|
|
try:
|
|
print(nvs2.get_i32("key2"))
|
|
except OSError as e:
|
|
print(e)
|
|
nvs2.set_i32("key2", 7654)
|
|
print(nvs.get_i32("key2"))
|
|
print(nvs2.get_i32("key2"))
|
|
|
|
# clean-up (the namespaces will remain)
|
|
nvs.erase_key("key2")
|
|
nvs.erase_key("blob1")
|
|
nvs.erase_key("blob2")
|
|
nvs2.erase_key("key2")
|
|
nvs.commit()
|