Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revisão | 7e55144de32d31267101ad4732581e79b241a749 (tree) |
---|---|
Hora | 2023-01-16 02:37:57 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
Added aux func to writers (Copy out IPython)
@@ -1,6 +1,6 @@ | ||
1 | 1 | default: all |
2 | 2 | |
3 | -CURRENT_TESTS = pytst/aux/test_1_pack_mk_tuple.py \ | |
3 | +CURRENT_TESTS = pytst/auxiliary/test_1_pack_mk_tuple.py \ | |
4 | 4 | |
5 | 5 | |
6 | 6 | all: current demo test pyanalyse XXX missing |
@@ -0,0 +1,5 @@ | ||
1 | +# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project | |
2 | +""" A collection of (small) auxiliary functions., | |
3 | + | |
4 | +They are used py CCastle, part of the CCastle code; but further not related to CCastle""" | |
5 | + |
@@ -0,0 +1,12 @@ | ||
1 | +# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project | |
2 | +""" | |
3 | +""" | |
4 | +from typing import Any | |
5 | + | |
6 | +def mk_tuple(tuple_list_or_element) -> list[Any]: | |
7 | + """Expect a sequence of (ANY) element, or a single one, and make a tuple (RO-sequence) of it""" | |
8 | + | |
9 | + return (tuple_list_or_element if isinstance(tuple_list_or_element, tuple) | |
10 | + else tuple(tuple_list_or_element) if isinstance(tuple_list_or_element, list) | |
11 | + else () if isinstance(tuple_list_or_element, type(None)) | |
12 | + else tuple((tuple_list_or_element,)) ) |
@@ -0,0 +1,9 @@ | ||
1 | +# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project | |
2 | + | |
3 | +from castle.auxiliary.pack import mk_tuple | |
4 | + | |
5 | +def test_mk_tuple(): | |
6 | + assert mk_tuple(1) == (1,) | |
7 | + assert mk_tuple((1,)) == (1,) | |
8 | + assert mk_tuple([1,]) == (1,) | |
9 | + assert mk_tuple(None) == () |