micropython: add micropython component

This commit is contained in:
KY-zhang-X
2022-09-29 12:10:37 +08:00
parent 1514f1cb9b
commit dd76146324
2679 changed files with 354110 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
try:
import usys as sys
except ImportError:
import sys
print(sys.argv)

View File

@@ -0,0 +1,20 @@
# test builtin print function, using file= argument
try:
import usys as sys
except ImportError:
import sys
try:
sys.stdout
except AttributeError:
print("SKIP")
raise SystemExit
print(file=sys.stdout)
print("test", file=sys.stdout)
try:
print(file=1)
except (AttributeError, OSError): # CPython and uPy differ in error message
print("Error")

View File

@@ -0,0 +1,148 @@
{
"info": {
"maintainer": null,
"docs_url": "",
"requires_python": null,
"maintainer_email": null,
"cheesecake_code_kwalitee_id": null,
"keywords": null,
"package_url": "http://pypi.python.org/pypi/micropython-uasyncio",
"author": "MicroPython Developers",
"author_email": "micro-python@googlegroups.com",
"download_url": "UNKNOWN",
"platform": "UNKNOWN",
"version": "0.8.1",
"cheesecake_documentation_id": null,
"_pypi_hidden": false,
"description": "Lightweight asyncio-like library built around native Python coroutines, not around un-Python devices like callback mess.",
"release_url": "http://pypi.python.org/pypi/micropython-uasyncio/0.8.1",
"downloads": {
"last_month": 942,
"last_week": 173,
"last_day": 29
},
"_pypi_ordering": 6,
"classifiers": [],
"name": "micropython-uasyncio",
"bugtrack_url": null,
"license": "MIT",
"summary": "uasyncio module for MicroPython",
"home_page": "https://github.com/micropython/micropython/issues/405",
"stable_version": null,
"cheesecake_installability_id": null
},
"releases": {
"0.8": [
{
"has_sig": false,
"upload_time": "2015-01-01T23:52:41",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.tar.gz",
"md5_digest": "5df4d0d6b5fdb7c05fc418e5785e1336",
"downloads": 352,
"filename": "micropython-uasyncio-0.8.tar.gz",
"packagetype": "sdist",
"size": 2476
}
],
"0.6.2": [
{
"has_sig": false,
"upload_time": "2014-10-18T11:26:52",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.2.tar.gz",
"md5_digest": "c85fa7c11ef437f4e73c1fcd639db066",
"downloads": 475,
"filename": "micropython-uasyncio-0.6.2.tar.gz",
"packagetype": "sdist",
"size": 3262
}
],
"0.6.1": [
{
"has_sig": false,
"upload_time": "2014-10-11T02:21:17",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.1.tar.gz",
"md5_digest": "48cb0db7d8249d5f4a86db9c4b302d03",
"downloads": 507,
"filename": "micropython-uasyncio-0.6.1.tar.gz",
"packagetype": "sdist",
"size": 3237
}
],
"0.8.1": [
{
"has_sig": false,
"upload_time": "2015-01-04T20:02:03",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.1.tar.gz",
"md5_digest": "940d2647b8355289d54de543ff710b05",
"downloads": 249,
"filename": "micropython-uasyncio-0.8.1.tar.gz",
"packagetype": "sdist",
"size": 2484
}
],
"0.7": [
{
"has_sig": false,
"upload_time": "2014-10-23T22:02:11",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.7.tar.gz",
"md5_digest": "81250a0ee6649b5117878d5788ba96d3",
"downloads": 457,
"filename": "micropython-uasyncio-0.7.tar.gz",
"packagetype": "sdist",
"size": 2277
}
],
"0.7.1": [
{
"has_sig": false,
"upload_time": "2014-11-04T00:56:16",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.7.1.tar.gz",
"md5_digest": "21eda0501142830730cd82e1b0fa1a33",
"downloads": 412,
"filename": "micropython-uasyncio-0.7.1.tar.gz",
"packagetype": "sdist",
"size": 2474
}
],
"0.6": [
{
"has_sig": false,
"upload_time": "2014-08-27T00:17:45",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.tar.gz",
"md5_digest": "9d0b15108c5ade3a6902c9370c9dacf1",
"downloads": 668,
"filename": "micropython-uasyncio-0.6.tar.gz",
"packagetype": "sdist",
"size": 3246
}
]
},
"urls": [
{
"has_sig": false,
"upload_time": "2015-01-04T20:02:03",
"comment_text": "",
"python_version": "source",
"url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.1.tar.gz",
"md5_digest": "940d2647b8355289d54de543ff710b05",
"downloads": 249,
"filename": "micropython-uasyncio-0.8.1.tar.gz",
"packagetype": "sdist",
"size": 2484
}
]
}

View File

@@ -0,0 +1,3 @@
longer line1
line2
line3

View File

@@ -0,0 +1 @@
1234

View File

@@ -0,0 +1,49 @@
f = open("io/data/file1")
print(f.read(5))
print(f.readline())
print(f.read())
f = open("io/data/file1")
print(f.readlines())
f = open("io/data/file1", "r")
print(f.readlines())
f = open("io/data/file1", "rb")
print(f.readlines())
f = open("io/data/file1", mode="r")
print(f.readlines())
f = open("io/data/file1", mode="rb")
print(f.readlines())
# write() error
f = open("io/data/file1", "r")
try:
f.write("x")
except OSError:
print("OSError")
f.close()
# read(n) error on binary file
f = open("io/data/file1", "ab")
try:
f.read(1)
except OSError:
print("OSError")
f.close()
# read(n) error on text file
f = open("io/data/file1", "at")
try:
f.read(1)
except OSError:
print("OSError")
f.close()
# read() w/o args error
f = open("io/data/file1", "ab")
try:
f.read()
except OSError:
print("OSError")
f.close()
# close() on a closed file
f.close()

View File

@@ -0,0 +1,3 @@
f = open("io/data/file1")
for l in f:
print(l)

View File

@@ -0,0 +1,3 @@
f = open("io/data/file1")
b = f.read(100)
print(len(b))

View File

@@ -0,0 +1,4 @@
f = open("io/data/bigfile1")
b = f.read()
print(len(b))
print(b)

View File

@@ -0,0 +1,4 @@
f = open("io/data/bigfile1", "rb")
b = f.read(512)
print(len(b))
print(b)

View File

@@ -0,0 +1,14 @@
b = bytearray(30)
f = open("io/data/file1", "rb")
print(f.readinto(b))
print(b)
f = open("io/data/file2", "rb")
print(f.readinto(b))
print(b)
# readinto() on writable file
f = open("io/data/file1", "ab")
try:
f.readinto(bytearray(4))
except OSError:
print("OSError")

View File

@@ -0,0 +1,10 @@
b = bytearray(30)
f = open("io/data/file1", "rb")
# 2nd arg (length to read) is extension to CPython
print(f.readinto(b, 8))
print(b)
b = bytearray(4)
f = open("io/data/file1", "rb")
print(f.readinto(b, 8))
print(b)

View File

@@ -0,0 +1,4 @@
8
bytearray(b'longer l\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
4
bytearray(b'long')

View File

@@ -0,0 +1,14 @@
f = open("io/data/file1")
print(f.readline())
print(f.readline(3))
print(f.readline(4))
print(f.readline(5))
print(f.readline())
# readline() on writable file
f = open("io/data/file1", "ab")
try:
f.readline()
except OSError:
print("OSError")
f.close()

View File

@@ -0,0 +1,34 @@
f = open("io/data/file1", "rb")
print(f.seek(6))
print(f.read(5))
print(f.tell())
print(f.seek(0, 1))
print(f.read(4))
print(f.tell())
print(f.seek(-6, 2))
print(f.read(20))
print(f.tell())
print(f.seek(0, 0))
print(f.read(5))
print(f.tell())
f.close()
# test text mode
f = open("io/data/file1", "rt")
print(f.seek(6))
print(f.read(5))
print(f.tell())
f.close()
# seek closed file
f = open("io/data/file1", "r")
f.close()
try:
f.seek(1)
except (OSError, ValueError):
# CPy raises ValueError, uPy raises OSError
print("OSError or ValueError")

View File

@@ -0,0 +1,7 @@
try:
import usys as sys
except ImportError:
import sys
print(sys.stdin.fileno())
print(sys.stdout.fileno())

View File

@@ -0,0 +1,21 @@
f = open("io/data/file1")
with f as f2:
print(f2.read())
# File should be closed
try:
f.read()
except:
# Note: CPython and us throw different exception trying to read from
# close file.
print("can't read file after with")
# Regression test: test that exception in with initialization properly
# thrown and doesn't crash.
try:
with open("__non_existent", "r"):
pass
except OSError:
print("OSError")

View File

@@ -0,0 +1,37 @@
try:
import uos as os
except ImportError:
import os
if not hasattr(os, "remove"):
print("SKIP")
raise SystemExit
# cleanup in case testfile exists
try:
os.remove("testfile")
except OSError:
pass
# Should create a file
f = open("testfile", "a")
f.write("foo")
f.close()
f = open("testfile")
print(f.read())
f.close()
f = open("testfile", "a")
f.write("bar")
f.close()
f = open("testfile")
print(f.read())
f.close()
# cleanup
try:
os.remove("testfile")
except OSError:
pass

View File

@@ -0,0 +1,47 @@
try:
import uos as os
except ImportError:
import os
if not hasattr(os, "remove"):
print("SKIP")
raise SystemExit
# cleanup in case testfile exists
try:
os.remove("testfile")
except OSError:
pass
try:
f = open("testfile", "r+b")
print("Unexpectedly opened non-existing file")
except OSError:
print("Expected OSError")
pass
f = open("testfile", "w+b")
f.write(b"1234567890")
f.seek(0)
print(f.read())
f.close()
# Open with truncation
f = open("testfile", "w+b")
f.write(b"abcdefg")
f.seek(0)
print(f.read())
f.close()
# Open without truncation
f = open("testfile", "r+b")
f.write(b"1234")
f.seek(0)
print(f.read())
f.close()
# cleanup
try:
os.remove("testfile")
except OSError:
pass