summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py (renamed from third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py)75
1 files changed, 56 insertions, 19 deletions
diff --git a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py b/toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py
index 0b47c0fa5a..df3e3fab18 100644
--- a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py
+++ b/toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py
@@ -1,18 +1,37 @@
-import sys
import ctypes
-from rondpoint import *
+import sys
-dico = Dictionnaire(un=Enumeration.DEUX, deux=True, petit_nombre=0, gros_nombre=123456789)
+from rondpoint import (
+ Dictionnaire,
+ Enumeration,
+ EnumerationAvecDonnees,
+ Retourneur,
+ Stringifier,
+ copie_carte,
+ copie_dictionnaire,
+ copie_enumeration,
+ copie_enumerations,
+ switcheroo,
+)
+
+dico = Dictionnaire(
+ un=Enumeration.DEUX, deux=True, petit_nombre=0, gros_nombre=123456789
+)
copyDico = copie_dictionnaire(dico)
assert dico == copyDico
assert copie_enumeration(Enumeration.DEUX) == Enumeration.DEUX
-assert copie_enumerations([Enumeration.UN, Enumeration.DEUX]) == [Enumeration.UN, Enumeration.DEUX]
-assert copie_carte({
- "0": EnumerationAvecDonnees.ZERO(),
- "1": EnumerationAvecDonnees.UN(1),
- "2": EnumerationAvecDonnees.DEUX(2, "deux"),
-}) == {
+assert copie_enumerations([Enumeration.UN, Enumeration.DEUX]) == [
+ Enumeration.UN,
+ Enumeration.DEUX,
+]
+assert copie_carte(
+ {
+ "0": EnumerationAvecDonnees.ZERO(),
+ "1": EnumerationAvecDonnees.UN(1),
+ "2": EnumerationAvecDonnees.DEUX(2, "deux"),
+ }
+) == {
"0": EnumerationAvecDonnees.ZERO(),
"1": EnumerationAvecDonnees.UN(1),
"2": EnumerationAvecDonnees.DEUX(2, "deux"),
@@ -30,11 +49,13 @@ assert EnumerationAvecDonnees.UN(1) != EnumerationAvecDonnees.UN(2)
# lowering from rust and lifting into python.
rt = Retourneur()
+
def affirmAllerRetour(vals, identique):
for v in vals:
id_v = identique(v)
assert id_v == v, f"Round-trip failure: {v} => {id_v}"
+
MIN_I8 = -1 * 2**7
MAX_I8 = 2**7 - 1
MIN_I16 = -1 * 2**15
@@ -65,21 +86,29 @@ affirmAllerRetour([0x00000000, 0x12345678, 0xFFFFFFFF], rt.identique_u32)
# Longs
affirmAllerRetour([MIN_I64, -1, 0, 1, MAX_I64], rt.identique_i64)
-affirmAllerRetour([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], rt.identique_u64)
+affirmAllerRetour(
+ [0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], rt.identique_u64
+)
# Floats
affirmAllerRetour([0.0, 0.5, 0.25, 1.0, F32_ONE_THIRD], rt.identique_float)
# Doubles
affirmAllerRetour(
- [0.0, 0.5, 0.25, 1.0, 1.0 / 3, sys.float_info.max, sys.float_info.min],
- rt.identique_double
+ [0.0, 0.5, 0.25, 1.0, 1.0 / 3, sys.float_info.max, sys.float_info.min],
+ rt.identique_double,
)
# Strings
affirmAllerRetour(
- ["", "abc", "été", "ښي لاس ته لوستلو لوستل", "😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama"],
- rt.identique_string
+ [
+ "",
+ "abc",
+ "été",
+ "ښي لاس ته لوستلو لوستل",
+ "😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama",
+ ],
+ rt.identique_string,
)
# Test one way across the FFI.
@@ -97,11 +126,13 @@ affirmAllerRetour(
# together, we've shown the correctness of the return leg.
st = Stringifier()
+
def affirmEnchaine(vals, toString, rustyStringify=lambda v: str(v).lower()):
for v in vals:
str_v = toString(v)
assert rustyStringify(v) == str_v, f"String compare error {v} => {str_v}"
+
# Test the efficacy of the string transport from rust. If this fails, but everything else
# works, then things are very weird.
wellKnown = st.well_known_string("python")
@@ -124,7 +155,10 @@ affirmEnchaine([0x00000000, 0x12345678, 0xFFFFFFFF], st.to_string_u32)
# Longs
affirmEnchaine([MIN_I64, -1, 0, 1, MAX_I64], st.to_string_i64)
-affirmEnchaine([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], st.to_string_u64)
+affirmEnchaine(
+ [0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], st.to_string_u64
+)
+
# Floats
def rustyFloatToStr(v):
@@ -134,13 +168,16 @@ def rustyFloatToStr(v):
return str(int(v))
return str(v)
+
affirmEnchaine([0.0, 0.5, 0.25, 1.0], st.to_string_float, rustyFloatToStr)
-assert st.to_string_float(F32_ONE_THIRD) == "0.33333334" # annoyingly different string repr
+assert (
+ st.to_string_float(F32_ONE_THIRD) == "0.33333334"
+) # annoyingly different string repr
# Doubles
# TODO: float_info.max/float_info.min don't stringify-roundtrip properly yet, TBD.
affirmEnchaine(
- [0.0, 0.5, 0.25, 1.0, 1.0 / 3],
- st.to_string_double,
- rustyFloatToStr,
+ [0.0, 0.5, 0.25, 1.0, 1.0 / 3],
+ st.to_string_double,
+ rustyFloatToStr,
)