removed comments on 64MiB SPI flash causing build test issues

This commit is contained in:
Seth Kerr 2020-12-16 10:25:20 -05:00
parent c16b8f1ee5
commit ca757f2ead
239 changed files with 6751 additions and 16 deletions

32
.gitattributes 2 Normal file
View File

@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
#
# SPDX-License-Identifier: MIT
# Per default everything gets normalized and gets LF line endings on checkout.
* text eol=lf
# These will always have CRLF line endings on checkout.
*.vcxproj text eol=crlf
*.props text eol=crlf
*.bat text eol=crlf
# These are binary so should never be modified by git.
*.png binary
*.jpg binary
*.dxf binary
*.mpy binary
*.deb binary
*.zip binary
*.pdf binary
# These should also not be modified by git.
tests/basics/string_cr_conversion.py -text
tests/basics/string_crlf_conversion.py -text
ports/stm32/pybcdc.inf_template -text
ports/stm32/usbhost/** -text
ports/cc3200/hal/aes.c -text
ports/cc3200/hal/aes.h -text
ports/cc3200/hal/des.c -text
ports/cc3200/hal/i2s.c -text
ports/cc3200/hal/i2s.h -text
ports/cc3200/version.h -text

88
.gitignore 2 Normal file
View File

@ -0,0 +1,88 @@
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
#
# SPDX-License-Identifier: MIT
# Compiled Sources
###################
*.o
*.a
!atmel-samd/asf/**/*.a
*.elf
*.bin
*.map
*.hex
*.dis
*.exe
# Packages
############
dist/
*.egg-info
.eggs
# Logs and Databases
######################
*.log
# VIM Swap Files
######################
*.swp
# Build directory
######################
build/
bin/
circuitpython-stubs/
# Test failure outputs
######################
tests/*.exp
tests/*.out
# Python cache files
######################
__pycache__/
*.pyc
# Customized Makefile/project overrides
######################
GNUmakefile
user.props
# Sphinx output
###############
_build
# Generated rst files
######################
genrst/
/autoapi/
/shared-bindings/*/**/*.rst
# ctags and similar
###################
TAGS
# Merge leftovers
#################
*.orig
# Emacs backup files
####################
*~
*.DS_Store
**/*.DS_Store
*.icloud
# POEdit mo files
####################
*.mo
.vscode
.idea
# Python Virtual Environments
####################
.venv
.env

155
.gitmodules 2 Normal file
View File

@ -0,0 +1,155 @@
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
#
# SPDX-License-Identifier: MIT
[submodule "lib/axtls"]
path = lib/axtls
url = https://github.com/pfalcon/axtls
branch = micropython
[submodule "lib/libffi"]
path = lib/libffi
url = https://github.com/atgreen/libffi
[submodule "lib/berkeley-db-1.xx"]
path = lib/berkeley-db-1.xx
url = https://github.com/pfalcon/berkeley-db-1.xx
[submodule "lib/uzlib"]
path = lib/uzlib
url = https://github.com/pfalcon/uzlib
[submodule "tools/uf2"]
path = tools/uf2
url = https://github.com/Microsoft/uf2.git
[submodule "atmel-samd/frozen/Adafruit_CircuitPython_NeoPixel"]
path = frozen/Adafruit_CircuitPython_NeoPixel
url = https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
[submodule "frozen/Adafruit_CircuitPython_Thermistor"]
path = frozen/Adafruit_CircuitPython_Thermistor
url = https://github.com/adafruit/Adafruit_CircuitPython_Thermistor.git
[submodule "frozen/Adafruit_CircuitPython_LIS3DH"]
path = frozen/Adafruit_CircuitPython_LIS3DH
url = https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH.git
[submodule "frozen/Adafruit_CircuitPython_BusDevice"]
path = frozen/Adafruit_CircuitPython_BusDevice
url = https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git
[submodule "tools/python-semver"]
path = tools/python-semver
url = https://github.com/k-bx/python-semver.git
[submodule "atmel-samd/asf4"]
path = ports/atmel-samd/asf4
url = https://github.com/adafruit/asf4.git
branch = circuitpython
[submodule "tools/usb_descriptor"]
path = tools/usb_descriptor
url = https://github.com/adafruit/usb_descriptor.git
[submodule "lib/nrfutil"]
path = lib/nrfutil
url = https://github.com/adafruit/nRF52_nrfutil
[submodule "ports/atmel-samd/freetouch"]
path = ports/atmel-samd/freetouch
url = https://github.com/adafruit/Adafruit_FreeTouch.git
[submodule "frozen/Adafruit_CircuitPython_CircuitPlayground"]
path = frozen/Adafruit_CircuitPython_CircuitPlayground
url = https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git
[submodule "frozen/Adafruit_CircuitPython_HID"]
path = frozen/Adafruit_CircuitPython_HID
url = https://github.com/adafruit/Adafruit_CircuitPython_HID.git
[submodule "ports/atmel-samd/Adafruit_CircuitPython_Motor"]
path = frozen/Adafruit_CircuitPython_Motor
url = https://github.com/adafruit/Adafruit_CircuitPython_Motor.git
[submodule "ports/atmel-samd/Adafruit_CircuitPython_seesaw"]
path = frozen/Adafruit_CircuitPython_seesaw
url = https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git
[submodule "frozen/Adafruit_CircuitPython_IRRemote"]
path = frozen/Adafruit_CircuitPython_IRRemote
url = https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git
[submodule "frozen/Adafruit_CircuitPython_DotStar"]
path = frozen/Adafruit_CircuitPython_DotStar
url = https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git
[submodule "ports/atmel-samd/peripherals"]
path = ports/atmel-samd/peripherals
url = https://github.com/adafruit/samd-peripherals.git
[submodule "frozen/Adafruit_CircuitPython_Crickit"]
path = frozen/Adafruit_CircuitPython_Crickit
url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit
[submodule "ports/nrf/nrfx"]
path = ports/nrf/nrfx
url = https://github.com/adafruit/nrfx.git
[submodule "lib/tinyusb"]
path = lib/tinyusb
url = https://github.com/hathach/tinyusb.git
branch = master
fetchRecurseSubmodules = false
[submodule "tools/huffman"]
path = tools/huffman
url = https://github.com/tannewt/huffman.git
[submodule "tools/adabot"]
path = tools/adabot
url = https://github.com/adafruit/adabot.git
[submodule "tools/bitmap_font"]
path = tools/bitmap_font
url = https://github.com/adafruit/Adafruit_CircuitPython_BitmapFont.git
[submodule "tools/Tecate-bitmap-fonts"]
path = tools/Tecate-bitmap-fonts
url = https://github.com/Tecate/bitmap-fonts.git
[submodule "frozen/pew-pewpew-standalone-10.x"]
path = frozen/pew-pewpew-standalone-10.x
url = https://github.com/pewpew-game/pew-pewpew-standalone-10.x.git
[submodule "frozen/circuitpython-stage"]
path = frozen/circuitpython-stage
url = https://github.com/python-ugame/circuitpython-stage.git
[submodule "ports/cxd56/spresense-exported-sdk"]
path = ports/cxd56/spresense-exported-sdk
url = https://github.com/sonydevworld/spresense-exported-sdk.git
[submodule "frozen/Adafruit_CircuitPython_SD"]
path = frozen/Adafruit_CircuitPython_SD
url = https://github.com/adafruit/Adafruit_CircuitPython_SD.git
[submodule "lib/mp3"]
path = lib/mp3
url = https://github.com/adafruit/Adafruit_MP3
[submodule "ports/mimxrt10xx/sdk"]
path = ports/mimxrt10xx/sdk
url = https://github.com/adafruit/MIMXRT10xx_SDK
[submodule "frozen/Adafruit_CircuitPython_Register"]
path = frozen/Adafruit_CircuitPython_Register
url = https://github.com/adafruit/Adafruit_CircuitPython_Register.git
[submodule "extmod/ulab"]
path = extmod/ulab
url = https://github.com/v923z/micropython-ulab
[submodule "frozen/Adafruit_CircuitPython_ESP32SPI"]
path = frozen/Adafruit_CircuitPython_ESP32SPI
url = https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI
[submodule "frozen/Adafruit_CircuitPython_Requests"]
path = frozen/Adafruit_CircuitPython_Requests
url = https://github.com/adafruit/Adafruit_CircuitPython_Requests
[submodule "ports/stm/st_driver"]
path = ports/stm/st_driver
url = https://github.com/hathach/st_driver.git
[submodule "lib/protomatter"]
path = lib/protomatter
url = https://github.com/adafruit/Adafruit_Protomatter
[submodule "frozen/Adafruit_CircuitPython_LSM6DS"]
path = frozen/Adafruit_CircuitPython_LSM6DS
url = https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS
[submodule "frozen/Adafruit_CircuitPython_FocalTouch"]
path = frozen/Adafruit_CircuitPython_FocalTouch
url = https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch
[submodule "frozen/Adafruit_CircuitPython_DS3231"]
path = frozen/Adafruit_CircuitPython_DS3231
url = https://github.com/adafruit/Adafruit_CircuitPython_DS3231
[submodule "frozen/Adafruit_CircuitPython_DRV2605"]
path = frozen/Adafruit_CircuitPython_DRV2605
url = https://github.com/adafruit/Adafruit_CircuitPython_DRV2605
[submodule "frozen/Adafruit_CircuitPython_BLE"]
path = frozen/Adafruit_CircuitPython_BLE
url = https://github.com/adafruit/Adafruit_CircuitPython_BLE
[submodule "frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center"]
path = frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center
url = https://github.com/adafruit/Adafruit_CircuitPython_BLE_Apple_Notification_Center
[submodule "frozen/Adafruit_CircuitPython_RFM9x"]
path = frozen/Adafruit_CircuitPython_RFM9x
url = https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git
[submodule "frozen/Adafruit_CircuitPython_RFM69"]
path = frozen/Adafruit_CircuitPython_RFM69
url = https://github.com/adafruit/Adafruit_CircuitPython_RFM69.git
[submodule "ports/esp32s2/esp-idf"]
path = ports/esp32s2/esp-idf
url = https://github.com/jepler/esp-idf.git

112
.mailmap 2 Normal file
View File

@ -0,0 +1,112 @@
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
#
# SPDX-License-Identifier: Unlicense
Alexander Steffen <devel.20.webmeister@spamgourmet.com>
Alexander Steffen <devel.20.webmeister@spamgourmet.com> <Alexander.Steffen@infineon.com>
Alexander Steffen <devel.20.webmeister@spamgourmet.com> <webmeister@users.noreply.github.com>
Benjamin Vernoux <bvernoux@gmail.com>
Brent Rubell <robots199@me.com>
Brent Rubell <robots199@me.com> <brent@xn.home>
Brent Rubell <robots199@me.com> <brentru@users.noreply.github.com>
Carlos <carlos.santiago.diaz@gmail.com>
Chris Packham <judge.packham@gmail.com>
Chris Packham <judge.packham@gmail.com> <chris.packham@alliedtelesis.co.nz>
Damiano Mazzella <damianomazzella@gmail.com>
Damien George <damien.p.george@gmail.com>
Dan Halbert <halbert@adafruit.com>
Dan Halbert <halbert@adafruit.com> <halbert@halwitz.org>
Daniel Pollard <daniel@learnweaver.com>
Daniel Pollard <daniel@learnweaver.com> <daniel.pollard@learnweaver.com>
Daniel Tralamazza <daniel@tralamazza.com>
Daniel Tralamazza <daniel@tralamazza.com> <tralamazza@users.noreply.github.com>
David Glaude <david.glaude@gmail.com>
David Glaude <david.glaude@gmail.com> <dglaude@users.noreply.github.com>
George Waters <gwatersdev@gmail.com>
George Waters <gwatersdev@gmail.com> <george@georgeh2os.com>
Ha Thach <thach@tinyusb.org>
Henrik Sölver <henrik.solver@gmail.com>
Ilya Dmitrichenko <errordeveloper@gmail.com>
Ilya Dmitrichenko <errordeveloper@gmail.com> <ilya@xively.com>
Jason Pecor <14111408+jpecor@users.noreply.github.com>
Jeff Epler <jepler@gmail.com>
Jeff Epler <jepler@gmail.com> <jeff@adafruit.com>
Jeff Epler <jepler@gmail.com> <jepler@de11.u>
Jeff Epler <jepler@gmail.com> <jepler@unpythonic.net>
Jerry Needell <jerryneedell@gmail.com>
Joe Bakalor <jmbakalor@gmail.com>
Josh Klar <josh@klar.sh>
Josh Klar <josh@klar.sh> <j@iv597.com>
Juan Biondi <juanernestobiondi@gmail.com>
Juan Biondi <juanernestobiondi@gmail.com> <juanernestobiondi@hotmail.com>
KalbeAbbas <kalbeabbas142@gmail.com>
KalbeAbbas <kalbeabbas142@gmail.com> <kalbeabbas@142@gmail.com>
Kamil Tomaszewski <kamil.tomaszewski@sony.com>
Kamil Tomaszewski <kamil.tomaszewski@sony.com> <46525824+kamtom480@users.noreply.github.com>
Kattni <kattni@adafruit.com> <kattni@kittyfish.org>
Kattni Rembor <kattni@adafruit.com>
Kenny <WarriorOfWire@users.noreply.github.com>
Kenny <WarriorOfWire@users.noreply.github.com> <3454741+WarriorOfWire@users.noreply.github.com>
Kevin Townsend <contact@microbuilder.eu>
Kevin Townsend <contact@microbuilder.eu> <microbuilder@users.noreply.github.com>
Krzysztof Blazewicz <blazewicz.krzysztof@gmail.com>
Krzysztof Blazewicz <blazewicz.krzysztof@gmail.com> <krzysztof.blazewicz@uxeon.com>
Li Weiwei <liweiwei@yeweitech.org>
Li Weiwei <liweiwei@yeweitech.org> <liweiwei@yeweitech.com>
Limor "Ladyada" Fried <limor@ladyada.net>
Limor "Ladyada" Fried <limor@ladyada.net> <ladyada>
Lucian Copeland <hierophect@gmail.com>
Lucian Copeland <hierophect@gmail.com> <hierophect@Lucians-MacBook-Air-2.local>
Mark Olsson <post@markolsson.se>
Mark Olsson <post@markolsson.se> <mark@markolsson.se>
Matt Land <matt-land@users.noreply.github.com>
Matt Land <matt-land@users.noreply.github.com> <mland@sparefoot.com>
Matt Wozniski <godlygeek+git@gmail.com>
Matt Wozniski <godlygeek+git@gmail.com> <mwozniski@bloomberg.net>
Melissa LeBlanc-Williams <melissa@adafruit.com>
Melissa LeBlanc-Williams <melissa@adafruit.com> <melissa@melissagirl.com>
Metallicow <metaliobovinus@gmail.com>
Metallicow <metaliobovinus@gmail.com> <edg62702@yahoo.com>
Peter Hinch <peter@hinch.me.uk>
Peter Hinch <peter@hinch.me.uk> <peterhinch@users.noreply.github.com>
Radomir Dopieralski <openstack@sheep.art.pl>
Radomir Dopieralski <openstack@sheep.art.pl> <deshipu@users.noreply.github.com>
Rafa Gould <rafagoulds@gmail.com>
Rafa Gould <rafagoulds@gmail.com> <50337143+rafa-gould@users.noreply.github.com>
Ryan Shaw <ryan.shaw@wisetechglobal.com>
Ryan Shaw <ryan.shaw@wisetechglobal.com> <ryannathans@hotmail.com>
Sabas <s@electroniccats.com>
Sabas <s@electroniccats.com> <s@theinventorhouse.org>
Sabas <s@electroniccats.com> <sabasjimenez@gmail.com>
Scott Shawcroft <scott@adafruit.com>
Scott Shawcroft <scott@adafruit.com> <devnull@unpythonic.net>
Scott Shawcroft <scott@adafruit.com> <scott.shawcroft@gmail.com>
Scott Shawcroft <scott@adafruit.com> <scott@chickadee.tech>
Scott Shawcroft <scott@adafruit.com> <scott@tannewt.org>
Sebastian Plamauer <oeplse@gmail.com>
Sebastian Plamauer <oeplse@gmail.com> <oepse@gmail.com>
Senuros <Senuros@users.noreply.github.com>
Senuros <Senuros@users.noreply.github.com> <senuros@noreply.github.com>
Stewart Colborne <tscolborne@outlook.com>
Stewart Colborne <tscolborne@outlook.com> <tscolborne@hotmail.com>
TG-Techie <TGTechie01@gmail.com>
TG-Techie <TGTechie01@gmail.com> <39284876+TG-Techie@users.noreply.github.com>
Thea Flowers <me@thea.codes>
Thea Flowers <me@thea.codes> <theaflowers@google.com>
Tobias Badertscher <badi@baerospace.ch>
Tobias Badertscher <badi@baerospace.ch> <python@baerospace.ch>
danicampora <danicampora@gmail.com>
danicampora <danicampora@gmail.com> <daniel@wipy.io>
dherrada <dylan.herrada@gmail.com>
dherrada <dylan.herrada@gmail.com> <33632497+dherrada@users.noreply.github.com>
dherrada <dylan.herrada@gmail.com> <=>
glennrub <glennbakke@gmail.com>
retoc <retoc@users.noreply.github.com>
retoc <retoc@users.noreply.github.com> <Retoc@noreply.github.com>
siddacious <nospam187+github@gmail.com>
siddacious <nospam187+github@gmail.com> <bsiepert@gmail.com>
siddacious <nospam187+github@gmail.com> <bsiepert@lbl.gov>
sommersoft <sommersoft@gmail.com>
sommersoft <sommersoft@gmail.com> <sommersoft@users.noreply.github.com>
stijn <stijn@ignitron.net>
stijn <stijn@ignitron.net> <stinos@zoho.com>

11
mpy-cross/.gitignore 2 Normal file
View File

@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
#
# SPDX-License-Identifier: MIT
/build-*
/mpy-cross
/mpy-cross.static
/mpy-cross.static.exe
/mpy-cross.static-raspbian
/mpy-cross.fuzz
/pitools

View File

@ -0,0 +1,2 @@
tools/bossac* binary
asf/**/*.a binary

View File

@ -0,0 +1 @@
build-*/

View File

@ -0,0 +1,47 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// This file defines board specific functions.
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H
#include <stdbool.h>
#include "py/mpconfig.h"
// Initializes board related state once on start up.
void board_init(void);
// Returns true if the user initiates safe mode in a board specific way.
// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific
// way.
bool board_requests_safe_mode(void);
// Reset the state of off MCU components such as neopixels.
void reset_board(void);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H

View File

@ -589,22 +589,40 @@ typedef struct {
// Settings for the Macronix MX25L51245G 64MiB SPI flash.
// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf
// Will finish this addition in a future PR. All the stuff is there, just need to test in the wild.
//#define MX25L25645G {\
// .total_size = (1 << 25), /* 32 MiB */ \
// .start_up_time_us = 5000, \
// .manufacturer_id = 0x9f, \
// .memory_type = 0xab, \
// .capacity = 0x90, \
// .max_clock_speed_mhz = 133, \
// .quad_enable_bit_mask = 0xaf, \
// .has_sector_protection = false, \
// .supports_fast_read = true, \
// .supports_qspi = true, \
// .supports_qspi_writes = true, \
// .write_status_register_split = false, \
// .single_status_byte = true, \
//}
#define MX25L25645G {\
.total_size = (1 << 25), /* 32 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0x9f, \
.memory_type = 0xab, \
.capacity = 0x90, \
.max_clock_speed_mhz = 133, \
.quad_enable_bit_mask = 0xaf, \
.has_sector_protection = false, \
.supports_fast_read = true, \
.supports_qspi = true, \
.supports_qspi_writes = true, \
.write_status_register_split = false, \
.single_status_byte = true, \
}
// Settings for the Macronix MX25L12833F 16MiB SPI flash
// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7447/MX25L12833F,%203V,%20128Mb,%20v1.0.pdf
#define MX25L12833F {\
.total_size = (1UL << 24), /* 16 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xc2, \
.memory_type = 0x20, \
.capacity = 0x18, \
.max_clock_speed_mhz = 133, \
.quad_enable_bit_mask = 0x40, \
.has_sector_protection = true, \
.supports_fast_read = true, \
.supports_qspi = true, \
.supports_qspi_writes = true, \
.write_status_register_split = false, \
.single_status_byte = true, \
}
// Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf

18
tests/README 2 Normal file
View File

@ -0,0 +1,18 @@
This directory contains tests for various functionality areas of MicroPython.
To run all stable tests, run "run-tests" script in this directory.
Tests of capabilities not supported on all platforms should be written
to check for the capability being present. If it is not, the test
should merely output 'SKIP' followed by the line terminator, and call
sys.exit() to raise SystemExit, instead of attempting to test the
missing capability. The testing framework (run-tests in this
directory, test_main.c in qemu_arm) recognizes this as a skipped test.
There are a few features for which this mechanism cannot be used to
condition a test. The run-tests script uses small scripts in the
feature_check directory to check whether each such feature is present,
and skips the relevant tests if not.
When creating new tests, anything that relies on float support should go in the
float/ subdirectory. Anything that relies on import x, where x is not a built-in
module, should go in the import/ subdirectory.

89
tests/extmod 2/btree1.py Normal file
View File

@ -0,0 +1,89 @@
try:
import btree
import uio
import uerrno
except ImportError:
print("SKIP")
raise SystemExit
#f = open("_test.db", "w+b")
f = uio.BytesIO()
db = btree.open(f, pagesize=512)
db[b"foo3"] = b"bar3"
db[b"foo1"] = b"bar1"
db[b"foo2"] = b"bar2"
db[b"bar1"] = b"foo1"
dbstr = str(db)
print(dbstr[:7], dbstr[-1:])
print(db[b"foo2"])
try:
print(db[b"foo"])
except KeyError:
print("KeyError")
print(db.get(b"foo"))
print(db.get(b"foo", b"dflt"))
del db[b"foo2"]
try:
del db[b"foo"]
except KeyError:
print("KeyError")
for k, v in db.items():
print((k, v))
print("---")
for k, v in db.items(None, None):
print((k, v))
print("---")
for k, v in db.items(b"f"):
print((k, v))
print("---")
for k, v in db.items(b"f", b"foo3"):
print((k, v))
print("---")
for k, v in db.items(None, b"foo3"):
print((k, v))
print("---")
for k, v in db.items(b"f", b"foo3", btree.INCL):
print((k, v))
print("---")
for k, v in db.items(None, None, btree.DESC):
print((k, v))
print(db.seq(1, b"foo1"))
print(db.seq(1, b"qux"))
try:
db.seq(b"foo1")
except OSError as e:
print(e.args[0] == uerrno.EINVAL)
print(list(db.keys()))
print(list(db.values()))
for k in db:
print(k)
db.put(b"baz1", b"qux1")
print("foo1", "foo1" in db)
print("foo2", "foo2" in db)
print("baz1", "baz1" in db)
try:
print(db + db[b"foo1"])
except TypeError:
print("TypeError")
db.flush()
db.close()
f.close()

109
tests/extmod 2/framebuf1.py Normal file
View File

@ -0,0 +1,109 @@
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
maps = {framebuf.MONO_VLSB : 'MONO_VLSB',
framebuf.MONO_HLSB : 'MONO_HLSB',
framebuf.MONO_HMSB : 'MONO_HMSB'}
for mapping in maps.keys():
for x in range(size):
buf[x] = 0
fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
print(maps[mapping])
# access as buffer
print(memoryview(fbuf)[0])
# fill
fbuf.fill(1)
print(buf)
fbuf.fill(0)
print(buf)
# put pixel
fbuf.pixel(0, 0, 1)
fbuf.pixel(4, 0, 1)
fbuf.pixel(0, 15, 1)
fbuf.pixel(4, 15, 1)
print(buf)
# clear pixel
fbuf.pixel(4, 15, 0)
print(buf)
# get pixel
print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
# hline
fbuf.fill(0)
fbuf.hline(0, 1, w, 1)
print('hline', buf)
# vline
fbuf.fill(0)
fbuf.vline(1, 0, h, 1)
print('vline', buf)
# rect
fbuf.fill(0)
fbuf.rect(1, 1, 3, 3, 1)
print('rect', buf)
#fill rect
fbuf.fill(0)
fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
fbuf.fill_rect(1, 1, 3, 3, 1)
print('fill_rect', buf)
# line
fbuf.fill(0)
fbuf.line(1, 1, 3, 3, 1)
print('line', buf)
# line steep negative gradient
fbuf.fill(0)
fbuf.line(3, 3, 2, 1, 1)
print('line', buf)
# scroll
fbuf.fill(0)
fbuf.pixel(2, 7, 1)
fbuf.scroll(0, 1)
print(buf)
fbuf.scroll(0, -2)
print(buf)
fbuf.scroll(1, 0)
print(buf)
fbuf.scroll(-1, 0)
print(buf)
fbuf.scroll(2, 2)
print(buf)
# print text
fbuf.fill(0)
fbuf.text("hello", 0, 0, 1)
print(buf)
fbuf.text("hello", 0, 0, 0) # clear
print(buf)
# char out of font range set to chr(127)
fbuf.text(str(chr(31)), 0, 0)
print(buf)
print()
# test invalid constructor, and stride argument
try:
fbuf = framebuf.FrameBuffer(buf, w, h, -1, w)
except ValueError:
print("ValueError")
# test legacy constructor
fbuf = framebuf.FrameBuffer1(buf, w, h)
fbuf = framebuf.FrameBuffer1(buf, w, h, w)
print(framebuf.MVLSB == framebuf.MONO_VLSB)

View File

@ -0,0 +1,59 @@
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
print(buf[y * w * 2:(y + 1) * w * 2])
print("-->8--")
w = 4
h = 5
buf = bytearray(w * h * 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
# fill
fbuf.fill(0xffff)
printbuf()
fbuf.fill(0x0000)
printbuf()
# put pixel
fbuf.pixel(0, 0, 0xeeee)
fbuf.pixel(3, 0, 0xee00)
fbuf.pixel(0, 4, 0x00ee)
fbuf.pixel(3, 4, 0x0ee0)
printbuf()
# get pixel
print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
# scroll
fbuf.fill(0x0000)
fbuf.pixel(2, 2, 0xffff)
printbuf()
fbuf.scroll(0, 1)
printbuf()
fbuf.scroll(1, 0)
printbuf()
fbuf.scroll(-1, -2)
printbuf()
w2 = 2
h2 = 3
buf2 = bytearray(w2 * h2 * 2)
fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
fbuf2.fill(0x0000)
fbuf2.pixel(0, 0, 0x0ee0)
fbuf2.pixel(0, 2, 0xee00)
fbuf2.pixel(1, 0, 0x00ee)
fbuf2.pixel(1, 2, 0xe00e)
fbuf.fill(0xffff)
fbuf.blit(fbuf2, 3, 3, 0x0000)
fbuf.blit(fbuf2, -1, -1, 0x0000)
fbuf.blit(fbuf2, 16, 16, 0x0000)
printbuf()

View File

@ -0,0 +1,57 @@
--8<--
33333333
33333333
33333333
33333333
33333333
-->8--
--8<--
00000000
00000000
00000000
00000000
00000000
-->8--
--8<--
10020000
00000000
00000000
00000000
30020000
-->8--
3 0
--8<--
00000000
00000000
00300000
00000000
00000000
-->8--
--8<--
00000000
00000000
00000000
00300000
00000000
-->8--
--8<--
00000000
00000000
00000000
00030000
00000000
-->8--
--8<--
00000000
00300000
00000000
00030000
00000000
-->8--
--8<--
33333333
23333333
33333333
33311333
33333333
-->8--

View File

@ -0,0 +1,53 @@
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
print(buf[y * w // 2:(y + 1) * w // 2])
print("-->8--")
w = 16
h = 8
buf = bytearray(w * h // 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
# fill
fbuf.fill(0x0f)
printbuf()
fbuf.fill(0xa0)
printbuf()
# put pixel
fbuf.pixel(0, 0, 0x01)
printbuf()
fbuf.pixel(w-1, 0, 0x02)
printbuf()
fbuf.pixel(w-1, h-1, 0x03)
printbuf()
fbuf.pixel(0, h-1, 0x04)
printbuf()
# get pixel
print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1))
print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1))
# fill rect
fbuf.fill_rect(0, 0, w, h, 0x0f)
printbuf()
fbuf.fill_rect(0, 0, w, h, 0xf0)
fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1)
printbuf()
fbuf.fill_rect(1, 0, w//2+1, 1, 0x10)
fbuf.fill_rect(1, 0, w//2, 1, 0xf1)
printbuf()
fbuf.fill_rect(1, 0, w//2, 1, 0x10)
fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf)
printbuf()
fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0)
fbuf.fill_rect(0, h-4, w//2, 4, 0xaf)
printbuf()
fbuf.fill_rect(0, h-4, w//2, 4, 0xb0)

View File

@ -0,0 +1,20 @@
# test subclassing framebuf.FrameBuffer
try:
import framebuf
except ImportError:
print('SKIP')
raise SystemExit
class FB(framebuf.FrameBuffer):
def __init__(self, n):
self.n = n
super().__init__(bytearray(2 * n * n), n, n, framebuf.RGB565)
def foo(self):
self.hline(0, 2, self.n, 0x0304)
fb = FB(n=3)
fb.pixel(0, 0, 0x0102)
fb.foo()
print(bytes(fb))

View File

@ -0,0 +1,28 @@
# test machine module
try:
try:
import umachine as machine
except ImportError:
import machine
machine.mem8
except:
print("SKIP")
raise SystemExit
print(machine.mem8)
try:
machine.mem16[1]
except ValueError:
print("ValueError")
try:
machine.mem16[1] = 1
except ValueError:
print("ValueError")
try:
del machine.mem8[0]
except TypeError:
print("TypeError")

View File

@ -0,0 +1,30 @@
try:
import umachine as machine
except ImportError:
import machine
try:
machine.PinBase
except AttributeError:
print("SKIP")
raise SystemExit
class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
self.v = False
def value(self, v=None):
print("value:", v)
if v is None:
self.v = not self.v
return int(self.v)
p = MyPin()
print(p.value())
print(p.value())
print(p.value())
p.value(1)
p.value(0)

View File

@ -0,0 +1,9 @@
__init__
value: None
1
value: None
0
value: None
1
value: 1
value: 0

View File

@ -0,0 +1,33 @@
from utime import ticks_diff, ticks_add
MAX = ticks_add(0, -1)
# Should be done like this to avoid small int overflow
MODULO_HALF = MAX // 2 + 1
# Invariants:
# if ticks_diff(a, b) = c,
# then ticks_diff(b, a) = -c
assert ticks_diff(1, 0) == 1, ticks_diff(1, 0)
assert ticks_diff(0, 1) == -1
assert ticks_diff(0, MAX) == 1
assert ticks_diff(MAX, 0) == -1
assert ticks_diff(0, MAX - 1) == 2
# Maximum "positive" distance
assert ticks_diff(MODULO_HALF, 1) == MODULO_HALF - 1, ticks_diff(MODULO_HALF, 1)
# Step further, and it becomes a negative distance
assert ticks_diff(MODULO_HALF, 0) == -MODULO_HALF
# Offsetting that in either direction doesn't affect the result
off = 100
# Cheating and skipping to use ticks_add() when we know there's no wraparound
# Real apps should use always it.
assert ticks_diff(MODULO_HALF + off, 1 + off) == MODULO_HALF - 1
assert ticks_diff(MODULO_HALF + off, 0 + off) == -MODULO_HALF
assert ticks_diff(MODULO_HALF - off, ticks_add(1, -off)) == MODULO_HALF - 1
assert ticks_diff(MODULO_HALF - off, ticks_add(0, -off)) == -MODULO_HALF
print("OK")

View File

@ -0,0 +1,22 @@
import utime
try:
utime.sleep_ms
except AttributeError:
print("SKIP")
raise SystemExit
utime.sleep_ms(1)
utime.sleep_us(1)
t0 = utime.ticks_ms()
t1 = utime.ticks_ms()
print(0 <= utime.ticks_diff(t1, t0) <= 1)
t0 = utime.ticks_us()
t1 = utime.ticks_us()
print(0 <= utime.ticks_diff(t1, t0) <= 500)
# ticks_cpu may not be implemented, at least make sure it doesn't decrease
t0 = utime.ticks_cpu()
t1 = utime.ticks_cpu()
print(utime.ticks_diff(t1, t0) >= 0)

View File

@ -0,0 +1,3 @@
True
True
True

View File

@ -0,0 +1,49 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
except ImportError:
print("SKIP")
raise SystemExit
print(binascii.a2b_base64(b''))
print(binascii.a2b_base64(b'Zg=='))
print(binascii.a2b_base64(b'Zm8='))
print(binascii.a2b_base64(b'Zm9v'))
print(binascii.a2b_base64(b'Zm9vYg=='))
print(binascii.a2b_base64(b'Zm9vYmE='))
print(binascii.a2b_base64(b'Zm9vYmFy'))
print(binascii.a2b_base64(b'AAECAwQFBgc='))
print(binascii.a2b_base64(b'CAkKCwwNDg8='))
print(binascii.a2b_base64(b'f4D/'))
print(binascii.a2b_base64(b'f4D+')) # convert '+'
print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk'))
# Ignore invalid characters and pad sequences
print(binascii.a2b_base64(b'Zm9v\n'))
print(binascii.a2b_base64(b'Zm\x009v\n'))
print(binascii.a2b_base64(b'Zm9v=='))
print(binascii.a2b_base64(b'Zm9v==='))
print(binascii.a2b_base64(b'Zm9v===YmFy'))
# Unicode strings can be decoded
print(binascii.a2b_base64(u'Zm9v===YmFy'))
try:
print(binascii.a2b_base64(b'abc'))
except ValueError:
print("ValueError")
try:
print(binascii.a2b_base64(b'abcde='))
except ValueError:
print("ValueError")
try:
print(binascii.a2b_base64(b'ab*d'))
except ValueError:
print("ValueError")
try:
print(binascii.a2b_base64(b'ab=cdef='))
except ValueError:
print("ValueError")

View File

@ -0,0 +1,17 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
except ImportError:
print("SKIP")
raise SystemExit
print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
print(binascii.hexlify(b'\x7f\x80\xff'))
print(binascii.hexlify(b'1234ABCDabcd'))
try:
binascii.hexlify('')
except TypeError:
print("TypeError")

View File

@ -0,0 +1,11 @@
b'\xff\xff\xff\x7f5678abcd'
b'\x00\x00\x00\x805678abcd'
b'\x03\x02\x01\xff5678abcd'
b'\x03\x02\x01\xff\x00\x00\x00\x80\x00\x00\x00\x00'
b'\x03\x02\x01\xff\x00\x00\x00\x00\x01\x00\x00\x00'
=
b'\x7f\xff\xff\xff5678abcd'
b'\x80\x00\x00\x005678abcd'
b'\xff\x01\x02\x035678abcd'
b'\xff\x01\x02\x03\x00\x00\x00\x00\x80\x00\x00\x00'
b'\xff\x01\x02\x03\x00\x00\x00\x01\x00\x00\x00\x00'

View File

@ -0,0 +1,89 @@
import sys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if sys.byteorder != "little":
print("SKIP")
raise SystemExit
desc = {
# arr is array at offset 0, of UINT8 elements, array size is 2
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
# aligned
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
}
data = bytearray(8)
S = uctypes.struct(uctypes.addressof(data), desc)
# assign byte
S.arr[0] = 0x11
print(hex(S.arr[0]))
assert hex(S.arr[0]) == "0x11"
# assign word
S.arr3[0] = 0x2233
print(hex(S.arr3[0]))
assert hex(S.arr3[0]) == "0x2233"
# assign word, with index
S.arr3[1] = 0x4455
print(hex(S.arr3[1]))
assert hex(S.arr3[1]) == "0x4455"
# assign long, aligned
S.arr5[0] = 0x66778899
print(hex(S.arr5[0]))
assert hex(S.arr5[0]) == "0x66778899"
print(S.arr5[0] == S.arr7[0].l)
assert S.arr5[0] == S.arr7[0].l
# assign int8
S.arr8[0] = 0x11
print(hex(S.arr8[0]))
assert hex(S.arr8[0]) == "0x11"
# assign int16
S.arr9[0] = 0x1122
print(hex(S.arr9[0]))
assert hex(S.arr9[0]) == "0x1122"
# assign int32
S.arr10[0] = 0x11223344
print(hex(S.arr10[0]))
assert hex(S.arr10[0]) == "0x11223344"
# index out of range
try:
print(S.arr8[2])
except IndexError:
print("IndexError")
# syntax error in descriptor
try:
S.arr13[0].l = 0x11
except TypeError:
print("TypeError")
# operation not supported
try:
S.arr13[0] = 0x11
except TypeError:
print("TypeError")

View File

@ -0,0 +1,11 @@
0x11
0x2233
0x4455
0x66778899
True
0x11
0x1122
0x11223344
IndexError
TypeError
TypeError

View File

@ -0,0 +1,43 @@
import sys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if sys.byteorder != "little":
print("SKIP")
raise SystemExit
desc = {
# arr is array at offset 0, of UINT8 elements, array size is 2
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
# aligned
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
}
data = bytearray(8)
S = uctypes.struct(uctypes.addressof(data), desc)
# assign int64
S.arr11[0] = 0x11223344
print(hex(S.arr11[0]))
assert hex(S.arr11[0]) == "0x11223344"
# assign uint64
S.arr12[0] = 0x11223344
print(hex(S.arr12[0]))
assert hex(S.arr12[0]) == "0x11223344"

View File

@ -0,0 +1,22 @@
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
"arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2),
}
data = bytearray(b"01234567")
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
# Arrays of UINT8 are accessed as bytearrays
print(S.arr)
# But not INT8, because value range is different
print(type(S.arr2))
# convert to buffer
print(bytearray(S))

View File

@ -0,0 +1,10 @@
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
data = bytearray(b'01234567')
print(uctypes.bytes_at(uctypes.addressof(data), 4))
print(uctypes.bytearray_at(uctypes.addressof(data), 4))

View File

@ -0,0 +1,2 @@
b'0123'
bytearray(b'0123')

View File

@ -0,0 +1,37 @@
# test general errors with uctypes
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
data = bytearray(b"01234567")
# del subscr not supported
S = uctypes.struct(uctypes.addressof(data), {})
try:
del S[0]
except TypeError:
print('TypeError')
# list is an invalid descriptor
S = uctypes.struct(uctypes.addressof(data), [])
try:
S.x
except TypeError:
print('TypeError')
# can't access attribute with invalid descriptor
S = uctypes.struct(uctypes.addressof(data), {'x':[]})
try:
S.x
except TypeError:
print('TypeError')
# can't assign to aggregate
S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)})
try:
S.x = 1
except TypeError:
print('TypeError')

View File

@ -0,0 +1,4 @@
TypeError
TypeError
TypeError
TypeError

View File

@ -0,0 +1,24 @@
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"f32": uctypes.FLOAT32 | 0,
"f64": uctypes.FLOAT64 | 0,
"uf64": uctypes.FLOAT64 | 2, # unaligned
}
data = bytearray(10)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
S.f32 = 12.34
print('%.4f' % S.f32)
S.f64 = 12.34
print('%.4f' % S.f64)
S.uf64 = 12.34
print('%.4f' % S.uf64)

View File

@ -0,0 +1,20 @@
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"f32": uctypes.FLOAT32 | 0,
"f64": uctypes.FLOAT64 | 0,
}
data = bytearray(8)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
S.f32 = 12.34
print('%.4f' % S.f32)
S.f64 = 12.34
print('%.4f' % S.f64)

View File

@ -0,0 +1,34 @@
import sys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if sys.byteorder != "little":
print("SKIP")
raise SystemExit
desc = {
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
"ptr16": (uctypes.PTR | 0, uctypes.UINT16),
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
}
bytes = b"01"
addr = uctypes.addressof(bytes)
buf = addr.to_bytes(uctypes.sizeof(desc), "little")
S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN)
print(S.ptr[0])
assert S.ptr[0] == ord("0")
print(S.ptr[1])
assert S.ptr[1] == ord("1")
print(hex(S.ptr16[0]))
assert hex(S.ptr16[0]) == "0x3130"
print(S.ptr2[0].b, S.ptr2[1].b)
print (S.ptr2[0].b, S.ptr2[1].b)
print(hex(S.ptr16[0]))
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)

View File

@ -0,0 +1,6 @@
48
49
0x3130
48 49
48 49
0x3130

View File

@ -0,0 +1,7 @@
2
2
4
TypeError
6
1
TypeError

View File

@ -0,0 +1,28 @@
try:
import uhashlib as hashlib
except ImportError:
try:
import hashlib
except ImportError:
# This is neither uPy, nor cPy, so must be uPy with
# uhashlib module disabled.
print("SKIP")
raise SystemExit
try:
hashlib.sha1
except AttributeError:
# SHA1 is only available on some ports
print("SKIP")
raise SystemExit
sha1 = hashlib.sha1(b'hello')
sha1.update(b'world')
print(sha1.digest())
sha1 = hashlib.sha1(b'hello')
try:
sha1.update(u'world')
except TypeError as e:
print("TypeError")
print(sha1.digest())

View File

@ -0,0 +1,30 @@
try:
from uio import StringIO
import ujson as json
except:
try:
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
s = StringIO()
json.dump(False, s)
print(s.getvalue())
s = StringIO()
json.dump({"a": (2, [3, None])}, s)
print(s.getvalue())
# dump to a small-int not allowed
try:
json.dump(123, 1)
except (AttributeError, OSError): # CPython and uPy have different errors
print('Exception')
# dump to an object not allowed
try:
json.dump(123, {})
except (AttributeError, OSError): # CPython and uPy have different errors
print('Exception')

View File

@ -0,0 +1,9 @@
# test uPy ujson behaviour that's not valid in CPy
try:
import ujson
except ImportError:
print("SKIP")
raise SystemExit
print(ujson.dumps(b'1234'))

View File

@ -0,0 +1,10 @@
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(1.2))

View File

@ -0,0 +1,4 @@
None
abcde
[False, True, 1, -2]
{'a': True}

View File

@ -0,0 +1,74 @@
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
def my_print(o):
if isinstance(o, dict):
print('sorted dict', sorted(o.items()))
else:
print(o)
my_print(json.loads('null'))
my_print(json.loads('false'))
my_print(json.loads('true'))
my_print(json.loads('1'))
my_print(json.loads('-2'))
my_print(json.loads('"abc\\u0064e"'))
my_print(json.loads('[]'))
my_print(json.loads('[null]'))
my_print(json.loads('[null,false,true]'))
my_print(json.loads(' [ null , false , true ] '))
my_print(json.loads('{}'))
my_print(json.loads('{"a":true}'))
my_print(json.loads('{"a":null, "b":false, "c":true}'))
my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}'))
my_print(json.loads('"abc\\bdef"'))
my_print(json.loads('"abc\\fdef"'))
my_print(json.loads('"abc\\ndef"'))
my_print(json.loads('"abc\\rdef"'))
my_print(json.loads('"abc\\tdef"'))
my_print(json.loads('"abc\\uabcd"'))
# whitespace handling
my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}'))
# loading nothing should raise exception
try:
json.loads('')
except ValueError:
print('ValueError')
# string which is not closed
try:
my_print(json.loads('"abc'))
except ValueError:
print('ValueError')
# unaccompanied closing brace
try:
my_print(json.loads(']'))
except ValueError:
print('ValueError')
# unspecified object type
try:
my_print(json.loads('a'))
except ValueError:
print('ValueError')
# bad property name
try:
my_print(json.loads('{{}:"abc"}'))
except ValueError:
print('ValueError')
# unexpected characters after white space
try:
my_print(json.loads('[null] a'))
except ValueError:
print('ValueError')

View File

@ -0,0 +1,17 @@
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
def my_print(o):
print('%.3f' % o)
my_print(json.loads('1.2'))
my_print(json.loads('1e2'))
my_print(json.loads('-2.3'))
my_print(json.loads('-2e3'))
my_print(json.loads('-2e-3'))

View File

@ -0,0 +1,29 @@
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
# check getrandbits returns a value within the bit range
for b in (1, 2, 3, 4, 16, 32):
for i in range(50):
assert random.getrandbits(b) < (1 << b)
# check that seed(0) gives a non-zero value
random.seed(0)
print(random.getrandbits(16) != 0)
# check that PRNG is repeatable
random.seed(1)
r = random.getrandbits(16)
random.seed(1)
print(random.getrandbits(16) == r)
# check that it throws an error for zero bits
try:
random.getrandbits(0)
except ValueError:
print('ValueError')

103
tests/extmod 2/ure1.py Normal file
View File

@ -0,0 +1,103 @@
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
r = re.compile(".+")
m = r.match("abc")
print(m.group(0))
try:
m.group(1)
except IndexError:
print("IndexError")
# conversion of re and match to string
str(r)
str(m)
r = re.compile("(.+)1")
m = r.match("xyz781")
print(m.group(0))
print(m.group(1))
try:
m.group(2)
except IndexError:
print("IndexError")
r = re.compile(r"\n")
m = r.match("\n")
print(m.group(0))
m = r.match("\\")
print(m)
r = re.compile(r"[\n-\r]")
m = r.match("\n")
print(m.group(0))
r = re.compile(r"[\]]")
m = r.match("]")
print(m.group(0))
print("===")
r = re.compile("[a-cu-z]")
m = r.match("a")
print(m.group(0))
m = r.match("z")
print(m.group(0))
m = r.match("d")
print(m)
m = r.match("A")
print(m)
print("===")
r = re.compile("[^a-cu-z]")
m = r.match("a")
print(m)
m = r.match("z")
print(m)
m = r.match("d")
print(m.group(0))
m = r.match("A")
print(m.group(0))
print("===")
# '-' character within character class block
print(re.match("[-a]+", "-a]d").group(0))
print(re.match("[a-]+", "-a]d").group(0))
print("===")
r = re.compile("o+")
m = r.search("foobar")
print(m.group(0))
try:
m.group(1)
except IndexError:
print("IndexError")
m = re.match(".*", "foo")
print(m.group(0))
m = re.search("w.r", "hello world")
print(m.group(0))
m = re.match('a+?', 'ab'); print(m.group(0))
m = re.match('a*?', 'ab'); print(m.group(0))
m = re.match('^ab$', 'ab'); print(m.group(0))
m = re.match('a|b', 'b'); print(m.group(0))
m = re.match('a|b|c', 'c'); print(m.group(0))
# Case where anchors fail to match
r = re.compile("^b|b$")
m = r.search("abc")
print(m)
try:
re.compile("*")
except:
print("Caught invalid regex")
# bytes objects
m = re.match(rb'a+?', b'ab'); print(m.group(0))

View File

@ -0,0 +1,15 @@
0: rsplit 5 (3)
2: any
3: jmp 0 (-5)
5: save 0
7: split 14 (5)
9: assert bol
10: char a
12: jmp 23 (9)
14: char b
16: class 1 0x30-0x39
20: namedclass w
22: assert eol
23: save 1
25: match
Bytes: 26, insts: 14

View File

@ -0,0 +1,25 @@
# test errors in regex
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
def test_re(r):
try:
re.compile(r)
print("OK")
except: # uPy and CPy use different errors, so just ignore the type
print("Error")
test_re(r'?')
test_re(r'*')
test_re(r'+')
test_re(r')')
test_re(r'[')
test_re(r'([')
test_re(r'([)')

View File

@ -0,0 +1,32 @@
# test named char classes
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
def print_groups(match):
print('----')
try:
i = 0
while True:
print(m.group(i))
i += 1
except IndexError:
pass
m = re.match(r'\w+','1234hello567 abc')
print_groups(m)
m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc')
print_groups(m)
m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc')
print_groups(m)
m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567')
print_groups(m)

View File

@ -0,0 +1 @@
RuntimeError

View File

@ -0,0 +1 @@
1-a2

View File

@ -0,0 +1,59 @@
# very basic test of ssl module, just to test the methods exist
try:
import uio as io
import ussl as ssl
except ImportError:
print("SKIP")
raise SystemExit
# create in client mode
try:
ss = ssl.wrap_socket(io.BytesIO())
except OSError as er:
print('wrap_socket:', repr(er))
# create in server mode (can use this object for further tests)
socket = io.BytesIO()
ss = ssl.wrap_socket(socket, server_side=1)
# print
print(repr(ss)[:12])
# setblocking
try:
ss.setblocking(False)
except NotImplementedError:
print('setblocking: NotImplementedError')
ss.setblocking(True)
# write
print(ss.write(b'aaaa'))
# read (underlying socket has no data)
print(ss.read(8))
# read (underlying socket has data, but it's bad data)
socket.write(b'aaaaaaaaaaaaaaaa')
socket.seek(0)
try:
ss.read(8)
except OSError as er:
print('read:', repr(er))
# close
ss.close()
# close 2nd time
ss.close()
# read on closed socket
try:
ss.read(10)
except OSError as er:
print('read:', repr(er))
# write on closed socket
try:
ss.write(b'aaaa')
except OSError as er:
print('write:', repr(er))

137
tests/extmod 2/utimeq1.py Normal file
View File

@ -0,0 +1,137 @@
# Test for utimeq module which implements task queue with support for
# wraparound time (utime.ticks_ms() style).
try:
from utime import ticks_add, ticks_diff
from utimeq import utimeq
except ImportError:
print("SKIP")
raise SystemExit
DEBUG = 0
MAX = ticks_add(0, -1)
MODULO_HALF = MAX // 2 + 1
if DEBUG:
def dprint(*v):
print(*v)
else:
def dprint(*v):
pass
# Try not to crash on invalid data
h = utimeq(10)
try:
h.push(1)
assert False
except TypeError:
pass
try:
h.pop(1)
assert False
except IndexError:
pass
# unsupported unary op
try:
~h
assert False
except TypeError:
pass
# pushing on full queue
h = utimeq(1)
h.push(1, 0, 0)
try:
h.push(2, 0, 0)
assert False
except IndexError:
pass
# popping into invalid type
try:
h.pop([])
assert False
except TypeError:
pass
# length
assert len(h) == 1
# peektime
assert h.peektime() == 1
# peektime with empty queue
try:
utimeq(1).peektime()
assert False
except IndexError:
pass
def pop_all(h):
l = []
while h:
item = [0, 0, 0]
h.pop(item)
#print("!", item)
l.append(tuple(item))
dprint(l)
return l
def add(h, v):
h.push(v, 0, 0)
dprint("-----")
#h.dump()
dprint("-----")
h = utimeq(10)
add(h, 0)
add(h, MAX)
add(h, MAX - 1)
add(h, 101)
add(h, 100)
add(h, MAX - 2)
dprint(h)
l = pop_all(h)
for i in range(len(l) - 1):
diff = ticks_diff(l[i + 1][0], l[i][0])
assert diff > 0
def edge_case(edge, offset):
h = utimeq(10)
add(h, ticks_add(0, offset))
add(h, ticks_add(edge, offset))
dprint(h)
l = pop_all(h)
diff = ticks_diff(l[1][0], l[0][0])
dprint(diff, diff > 0)
return diff
dprint("===")
diff = edge_case(MODULO_HALF - 1, 0)
assert diff == MODULO_HALF - 1
assert edge_case(MODULO_HALF - 1, 100) == diff
assert edge_case(MODULO_HALF - 1, -100) == diff
# We expect diff to be always positive, per the definition of heappop() which should return
# the smallest value.
# This is the edge case where this invariant breaks, due to assymetry of two's-complement
# range - there's one more negative integer than positive, so heappushing values like below
# will then make ticks_diff() return the minimum negative value. We could make heappop
# return them in a different order, but ticks_diff() result would be the same. Conclusion:
# never add to a heap values where (a - b) == MODULO_HALF (and which are >= MODULO_HALF
# ticks apart in real time of course).
dprint("===")
diff = edge_case(MODULO_HALF, 0)
assert diff == -MODULO_HALF
assert edge_case(MODULO_HALF, 100) == diff
assert edge_case(MODULO_HALF, -100) == diff
dprint("===")
diff = edge_case(MODULO_HALF + 1, 0)
assert diff == MODULO_HALF - 1
assert edge_case(MODULO_HALF + 1, 100) == diff
assert edge_case(MODULO_HALF + 1, -100) == diff
print("OK")

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1,33 @@
try:
import uzlib as zlib
import uio as io
except ImportError:
print("SKIP")
raise SystemExit
# Raw DEFLATE bitstream
buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00')
inp = zlib.DecompIO(buf, -8)
print(buf.seek(0, 1))
print(inp.read(1))
print(buf.seek(0, 1))
print(inp.read(2))
print(inp.read())
print(buf.seek(0, 1))
print(inp.read(1))
print(inp.read())
print(buf.seek(0, 1))
# zlib bitstream
inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'))
print(inp.read(10))
print(inp.read())
# zlib bitstream, wrong checksum
inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0'))
try:
print(inp.read())
except OSError as e:
print(repr(e))

View File

@ -0,0 +1,13 @@
16
b'h'
18
b'el'
b'lo'
31
b''
b''
31
b'hello'
b'hello'
ValueError
OSError(22,)

View File

@ -0,0 +1,139 @@
try:
import uerrno
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMFS:
SEC_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
return 0
def writeblocks(self, n, buf):
#print("writeblocks(%s, %x)" % (n, id(buf)))
for i in range(len(buf)):
self.data[n * self.SEC_SIZE + i] = buf[i]
return 0
def ioctl(self, op, arg):
#print("ioctl(%d, %r)" % (op, arg))
if op == 4: # BP_IOCTL_SEC_COUNT
return len(self.data) // self.SEC_SIZE
if op == 5: # BP_IOCTL_SEC_SIZE
return self.SEC_SIZE
try:
bdev = RAMFS(50)
except MemoryError:
print("SKIP")
raise SystemExit
uos.VfsFat.mkfs(bdev)
vfs = uos.VfsFat(bdev)
uos.mount(vfs, '/ramdisk')
uos.chdir('/ramdisk')
# file IO
f = open("foo_file.txt", "w")
print(str(f)[:17], str(f)[-1:])
f.write("hello!")
f.flush()
f.close()
f.close() # allowed
try:
f.write("world!")
except OSError as e:
print(e.args[0] == uerrno.EINVAL)
try:
f.read()
except OSError as e:
print(e.args[0] == uerrno.EINVAL)
try:
f.flush()
except OSError as e:
print(e.args[0] == uerrno.EINVAL)
try:
open("foo_file.txt", "x")
except OSError as e:
print(e.args[0] == uerrno.EEXIST)
with open("foo_file.txt", "a") as f:
f.write("world!")
with open("foo_file.txt") as f2:
print(f2.read())
print(f2.tell())
f2.seek(0, 0) # SEEK_SET
print(f2.read(1))
f2.seek(0, 1) # SEEK_CUR
print(f2.read(1))
f2.seek(2, 1) # SEEK_CUR
print(f2.read(1))
f2.seek(-2, 2) # SEEK_END
print(f2.read(1))
# using constructor of FileIO type to open a file
# no longer working with new VFS sub-system
#FileIO = type(f)
#with FileIO("/ramdisk/foo_file.txt") as f:
# print(f.read())
# dirs
vfs.mkdir("foo_dir")
try:
vfs.rmdir("foo_file.txt")
except OSError as e:
print(e.args[0] == 20) # uerrno.ENOTDIR
vfs.remove("foo_file.txt")
print(list(vfs.ilistdir()))
# Here we test that opening a file with the heap locked fails correctly. This
# is a special case because file objects use a finaliser and allocating with a
# finaliser is a different path to normal allocation. It would be better to
# test this in the core tests but there are no core objects that use finaliser.
import micropython
micropython.heap_lock()
try:
vfs.open('x', 'r')
except MemoryError:
print('MemoryError')
micropython.heap_unlock()
# Here we test that the finaliser is actually called during a garbage collection.
import gc
N = 4
for i in range(N):
n = 'x%d' % i
f = vfs.open(n, 'w')
f.write(n)
f = None # release f without closing
[0, 1, 2, 3] # use up Python stack so f is really gone
gc.collect() # should finalise all N files by closing them
for i in range(N):
with vfs.open('x%d' % i, 'r') as f:
print(f.read())

View File

@ -0,0 +1,18 @@
<io.TextIOWrapper >
True
True
True
True
hello!world!
12
h
e
o
d
True
[('foo_dir', 16384, 0, 0)]
MemoryError
x0
x1
x2
x3

View File

@ -0,0 +1,29 @@
/
['test.txt']
['test.txt']
(16384, 0, 0, 0, 0, 0, 0)
(16384, 0, 0, 0, 0, 0, 0)
(32768, 0, 0, 0, 0, 0, 5)
(32768, 0, 0, 0, 0, 0, 5)
hello
['test2.txt']
['test3.txt']
['test4.txt']
['test5.txt']
['test5.txt', 'dir']
['test5.txt', 'dir', 'dir2']
['subdir']
mkdir OSError True
mkdir OSError True
mkdir OSError True
mkdir OSError True
mkdir OSError True
(32768, 0, 0, 0, 0, 0, 5)
['sys', 'test5.txt', 'dir', 'dir2']
[]
[]
['sys', 'dir']
/
['sys']
[]
test_module!

View File

@ -0,0 +1,3 @@
[('file.txt', 32768, 0, 6)]
hello!
[]

View File

@ -0,0 +1,17 @@
True
True
label: LABEL TEST
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
getcwd: /
True
[('foo_file.txt', 32768, 0, 6)]
stat root: (16384, 0, 0, 0, 0, 0, 0, 946684800, 946684800, 946684800)
stat file: (32768, 0, 0, 0, 0, 0, 6)
True
True
getcwd: /foo_dir
[]
True
getcwd: /
[(b'foo_file.txt', 32768, 0, 6), (b'foo_dir', 16384, 0, 0)]
ENOENT: True

View File

@ -0,0 +1,14 @@
b'ping'
b'ping'
b'\x81\x04pong'
b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping'
b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong'
b'\x00\x00\x00\x00'
b''
b'\x81\x02\x88\x00'
b'ping'
b'pong'
0
1
2
ioctl: EINVAL: True

View File

@ -0,0 +1,4 @@
This directory doesn't contain real tests, but code snippets to detect
various interpreter features, which can't be/inconvenient to detecte by
other means. Scripts here are executed by run-tests at the beginning of
testsuite to decide what other test groups to run/exclude.

View File

@ -0,0 +1,3 @@
# check if async/await keywords are supported
async def foo():
await 1

View File

View File

@ -0,0 +1,2 @@
import sys
print(sys.byteorder)

View File

View File

@ -0,0 +1,5 @@
try:
complex
print("complex")
except NameError:
print("no")

View File

View File

@ -0,0 +1 @@
x = const(1)

View File

View File

@ -0,0 +1,5 @@
try:
extra_coverage
print('coverage')
except NameError:
print('no')

View File

View File

@ -0,0 +1,13 @@
# detect how many bits of precision the floating point implementation has
try:
float
except NameError:
print(0)
else:
if float('1.0000001') == float('1.0'):
print(30)
elif float('1e300') == float('inf'):
print(32)
else:
print(64)

View File

@ -0,0 +1 @@
64

View File

@ -0,0 +1,2 @@
# Check whether arbitrary-precision integers (MPZ) are supported
print(1000000000000000000000000000000000000000000000)

View File

@ -0,0 +1 @@
1000000000000000000000000000000000000000000000

View File

@ -0,0 +1,4 @@
# this test for the availability of native emitter
@micropython.native
def f():
pass

View File

@ -0,0 +1,3 @@
# Check for emacs keys in REPL
t = +11
t == 2

View File

@ -0,0 +1,7 @@
MicroPython \.\+ version
Use \.\+
>>> # Check for emacs keys in REPL
>>> t = \.\+
>>> t == 2
True
>>>

View File

@ -0,0 +1,9 @@
class Foo:
def __radd__(self, other):
pass
try:
5 + Foo()
except TypeError:
print("TypeError")

View File

View File

@ -0,0 +1,2 @@
# check if set literal syntax is supported
{1}

View File

View File

@ -0,0 +1,10 @@
# test construction of array from array with float type
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print(array('f', array('h', [1, 2])))
print(array('d', array('f', [1, 2])))

View File

@ -0,0 +1,25 @@
# test builtin hash function with float args
# these should hash to an integer with a specific value
for val in (
'0.0',
'-0.0',
'1.0',
'2.0',
'-12.0',
'12345.0',
):
print(val, hash(float(val)))
# just check that these values are hashable
for val in (
'0.1',
'-0.1',
'10.3',
'0.4e3',
'1e16',
'inf',
'-inf',
'nan',
):
print(val, type(hash(float(val))))

View File

@ -0,0 +1,31 @@
# test builtin min and max functions with float args
try:
min
max
except:
print("SKIP")
raise SystemExit
print(min(0, 1.0))
print(min(1.0, 0))
print(min(0, -1.0))
print(min(-1.0, 0))
print(max(0, 1.0))
print(max(1.0, 0))
print(max(0, -1.0))
print(max(-1.0, 0))
print(min(1.5, -1.5))
print(min(-1.5, 1.5))
print(max(1.5, -1.5))
print(max(-1.5, 1.5))
print(min([1, 2.9, 4, 0, -1, 2]))
print(max([1, 2.9, 4, 0, -1, 2]))
print(min([1, 2.9, 4, 6.5, -1, 2]))
print(max([1, 2.9, 4, 6.5, -1, 2]))
print(min([1, 2.9, 4, -6.5, -1, 2]))
print(max([1, 2.9, 4, -6.5, -1, 2]))

View File

@ -0,0 +1,11 @@
# test builtin pow function with float args
print(pow(0.0, 0.0))
print(pow(0, 1.0))
print(pow(1.0, 1))
print(pow(2.0, 3.0))
print(pow(2.0, -4.0))
print(pow(0.0, float('inf')))
print(pow(0.0, float('-inf')))
print(pow(0.0, float('nan')))

View File

@ -0,0 +1,24 @@
# test round() with floats
# check basic cases
tests = [
[0.0], [1.0], [0.1], [-0.1], [123.4], [123.6], [-123.4], [-123.6],
[1.234567, 5], [1.23456, 1], [1.23456, 0], [1234.56, -2]
]
for t in tests:
print(round(*t))
# check .5 cases
for i in range(11):
print(round((i - 5) / 2))
# test second arg
for i in range(-1, 3):
print(round(1.47, i))
# test inf and nan
for val in (float('inf'), float('nan')):
try:
round(val)
except (ValueError, OverflowError) as e:
print(type(e))

View File

@ -0,0 +1,4 @@
# test round() with floats that return large integers
for x in (-1e25, 1e25):
print('%.3g' % round(x))

View File

@ -0,0 +1,9 @@
# test construction of bytearray from array with float type
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print(bytearray(array('f', [1, 2.3])))

View File

@ -0,0 +1,9 @@
# test construction of bytearray from array with float type
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print(bytes(array('f', [1, 2.3])))

View File

@ -0,0 +1,55 @@
# test the functions imported from cmath
try:
from cmath import *
except ImportError:
print("SKIP")
raise SystemExit
# make sure these constants exist in cmath
print("%.5g" % e)
print("%.5g" % pi)
test_values_non_zero = []
base_values = (0.0, 0.5, 1.2345, 10.)
for r in base_values:
for i in base_values:
if r != 0. or i != 0.:
test_values_non_zero.append(complex(r, i))
if r != 0.:
test_values_non_zero.append(complex(-r, i))
if i != 0.:
test_values_non_zero.append(complex(r, -i))
if r != 0. and i != 0.:
test_values_non_zero.append(complex(-r, -i))
test_values = [complex(0., 0.),] + test_values_non_zero
print(test_values)
functions = [
('phase', phase, test_values),
('polar', polar, test_values),
('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))),
('exp', exp, test_values),
('log', log, test_values_non_zero),
('sqrt', sqrt, test_values),
('cos', cos, test_values),
('sin', sin, test_values),
]
for f_name, f, test_vals in functions:
print(f_name)
for val in test_vals:
if type(val) == tuple:
ret = f(*val)
else:
ret = f(val)
if type(ret) == float:
print("%.5g" % ret)
elif type(ret) == tuple:
print("%.5g %.5g" % ret)
else:
# some test (eg cmath.sqrt(-0.5)) disagree with CPython with tiny real part
real = ret.real
if abs(real) < 1e15:
real = 0.
print("complex(%.5g, %.5g)" % (real, ret.imag))

View File

@ -0,0 +1,31 @@
# test the special functions imported from cmath
try:
from cmath import *
log10
except (ImportError, NameError):
print("SKIP")
raise SystemExit
test_values_non_zero = []
base_values = (0.0, 0.5, 1.2345, 10.)
for r in base_values:
for i in base_values:
if r != 0. or i != 0.:
test_values_non_zero.append(complex(r, i))
if r != 0.:
test_values_non_zero.append(complex(-r, i))
if i != 0.:
test_values_non_zero.append(complex(r, -i))
if r != 0. and i != 0.:
test_values_non_zero.append(complex(-r, -i))
functions = [
('log10', log10, test_values_non_zero),
]
for f_name, f, test_vals in functions:
print(f_name)
for val in test_vals:
ret = f(val)
print("complex(%.5g, %.5g)" % (ret.real, ret.imag))

116
tests/float 2/complex1.py Normal file
View File

@ -0,0 +1,116 @@
# test basic complex number functionality
# constructor
print(complex(1))
print(complex(1.2))
print(complex(1.2j))
print(complex("1"))
print(complex("1.2"))
print(complex("1.2j"))
print(complex(1, 2))
print(complex(1j, 2j))
# unary ops
print(bool(1j))
print(+(1j))
print(-(1 + 2j))
# binary ops
print(1j + False)
print(1j + True)
print(1j + 2)
print(1j + 2j)
print(1j - 2)
print(1j - 2j)
print(1j * 2)
print(1j * 2j)
print(1j / 2)
print((1j / 2j).real)
print(1j / (1 + 2j))
ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
# comparison
print(1j == 1)
print(1j == 1j)
# comparison of nan is special
nan = float('nan') * 1j
print(nan == 1j)
print(nan == nan)
# builtin abs
print(abs(1j))
print("%.5g" % abs(1j + 2))
# builtin hash
print(hash(1 + 0j))
print(type(hash(1j)))
# float on lhs should delegate to complex
print(1.2 + 3j)
# negative base and fractional power should create a complex
ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag))
ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag))
# check printing of inf/nan
print(float('nan') * 1j)
print(float('-nan') * 1j)
print(float('inf') * (1 + 1j))
print(float('-inf') * (1 + 1j))
# can't assign to attributes
try:
(1j).imag = 0
except AttributeError:
print('AttributeError')
# can't convert rhs to complex
try:
1j + []
except TypeError:
print("TypeError")
# unsupported unary op
try:
~(1j)
except TypeError:
print("TypeError")
# unsupported binary op
try:
1j // 2
except TypeError:
print("TypeError")
# unsupported binary op
try:
1j < 2j
except TypeError:
print("TypeError")
#small int on LHS, complex on RHS, unsupported op
try:
print(1 | 1j)
except TypeError:
print('TypeError')
# zero division
try:
1j / 0
except ZeroDivisionError:
print("ZeroDivisionError")
# zero division via power
try:
0j ** -1
except ZeroDivisionError:
print("ZeroDivisionError")
try:
0j ** 1j
except ZeroDivisionError:
print("ZeroDivisionError")

View File

@ -0,0 +1,4 @@
# test basic complex number functionality
# convert bignum to complex on rhs
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))

119
tests/float 2/float1.py Normal file
View File

@ -0,0 +1,119 @@
# test basic float capabilities
# literals
print(.12)
print(1.)
print(1.2)
print(0e0)
print(0e+0)
print(0e-0)
# float construction
print(float(1.2))
print(float("1.2"))
print(float("+1"))
print(float("1e1"))
print(float("1e+1"))
print(float("1e-1"))
print(float("inf"))
print(float("-inf"))
print(float("INF"))
print(float("infinity"))
print(float("INFINITY"))
print(float("nan"))
print(float("-nan"))
print(float("NaN"))
try:
float("")
except ValueError:
print("ValueError")
try:
float("1e+")
except ValueError:
print("ValueError")
try:
float("1z")
except ValueError:
print("ValueError")
# construct from something with the buffer protocol
print(float(b"1.2"))
print(float(bytearray(b"3.4")))
# unary operators
print(bool(0.0))
print(bool(1.2))
print(+(1.2))
print(-(1.2))
# division of integers
x = 1 / 2
print(x)
# /= operator
a = 1
a /= 2
print(a)
# floor division
print(1.0 // 2)
print(2.0 // 2)
# comparison
print(1.2 <= 3.4)
print(1.2 <= -3.4)
print(1.2 >= 3.4)
print(1.2 >= -3.4)
# comparison of nan is special
nan = float('nan')
print(nan == 1.2)
print(nan == nan)
try:
1.0 / 0
except ZeroDivisionError:
print("ZeroDivisionError")
try:
1.0 // 0
except ZeroDivisionError:
print("ZeroDivisionError")
try:
1.2 % 0
except ZeroDivisionError:
print("ZeroDivisionError")
try:
0.0 ** -1
except ZeroDivisionError:
print("ZeroDivisionError")
# unsupported unary ops
try:
~1.2
except TypeError:
print("TypeError")
try:
1.2 in 3.4
except TypeError:
print("TypeError")
# small int on LHS, float on RHS, unsupported op
try:
print(1 | 1.0)
except TypeError:
print('TypeError')
# can't convert list to float
try:
float([])
except TypeError:
print("TypeError")
# test constant float with more than 255 chars
x = 1.84728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189
print("%.5f" % x)

View File

@ -0,0 +1,100 @@
# check cases converting float to int, requiring double precision float
try:
import ustruct as struct
except:
import struct
import sys
maxsize_bits = 0
maxsize = sys.maxsize
while maxsize:
maxsize >>= 1
maxsize_bits += 1
# work out configuration values
is_64bit = maxsize_bits > 32
# 0 = none, 1 = long long, 2 = mpz
ll_type = None
if is_64bit:
if maxsize_bits < 63:
ll_type = 0
else:
if maxsize_bits < 31:
ll_type = 0
if ll_type is None:
one = 1
if one << 65 < one << 62:
ll_type = 1
else:
ll_type = 2
# This case occurs with time.time() values
if ll_type != 0:
print(int(1418774543.))
print("%d" % 1418774543.)
if ll_type == 3:
print(int(2.**100))
print("%d" % 2.**100)
else:
print(int(1073741823.))
print("%d" % 1073741823.)
testpass = True
p2_rng = ((30,63,1024),(62,63,1024))[is_64bit][ll_type]
for i in range(0,p2_rng):
bitcnt = len(bin(int(2.**i))) - 3;
if i != bitcnt:
print('fail: 2**%u was %u bits long' % (i, bitcnt));
testpass = False
print("power of 2 test: %s" % (testpass and 'passed' or 'failed'))
testpass = True
p10_rng = ((9,18,23),(18,18,23))[is_64bit][ll_type]
for i in range(0,p10_rng):
digcnt = len(str(int(10.**i))) - 1;
if i != digcnt:
print('fail: 10**%u was %u digits long' % (i, digcnt));
testpass = False
print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))
def fp2int_test(num, name, should_fail):
try:
x = int(num)
passed = ~should_fail
except:
passed = should_fail
print('%s: %s' % (name, passed and 'passed' or 'failed'))
if ll_type != 2:
if ll_type == 0:
if is_64bit:
neg_bad_fp = -1.00000005*2.**62.
pos_bad_fp = 2.**62.
neg_good_fp = -2.**62.
pos_good_fp = 0.99999993*2.**62.
else:
neg_bad_fp = -1.00000005*2.**30.
pos_bad_fp = 2.**30.
neg_good_fp = -2.**30.
pos_good_fp = 0.9999999499*2.**30.
else:
neg_bad_fp = -0.51*2.**64.
pos_bad_fp = 2.**63.
neg_good_fp = -2.**63.
pos_good_fp = 1.9999998*2.**62.
fp2int_test(neg_bad_fp, 'neg bad', True)
fp2int_test(pos_bad_fp, 'pos bad', True)
fp2int_test(neg_good_fp, 'neg good', False)
fp2int_test(pos_good_fp, 'pos good', False)
else:
fp2int_test(-1.9999999999999981*2.**1023., 'large neg', False)
fp2int_test(1.9999999999999981*2.**1023., 'large pos', False)
fp2int_test(float('inf'), 'inf test', True)
fp2int_test(float('nan'), 'NaN test', True)
# test numbers < 1 (this used to fail; see issue #1044)
fp2int_test(0.0001, 'small num', False)
struct.pack('I', int(1/2))

Some files were not shown because too many files have changed in this diff Show More