Import LinuxCNC source tree
This commit is contained in:
109
tests/inifile/python_bindings/expected
Normal file
109
tests/inifile/python_bindings/expected
Normal file
@@ -0,0 +1,109 @@
|
||||
Missing section was missing
|
||||
Present section was present
|
||||
Missing variable was missing
|
||||
Present [section]variable was present
|
||||
Bool 1: True
|
||||
Bool 2: True
|
||||
Bool 3: True
|
||||
Bool 4: True
|
||||
Bool 5: False
|
||||
Bool 6: False
|
||||
Bool 7: False
|
||||
Bool 8: False
|
||||
Bool 9: None
|
||||
Int 1: 42
|
||||
Int 2: -42
|
||||
Int 3: 42
|
||||
Int 4: -42
|
||||
Int 5: 42
|
||||
Int 6: -42
|
||||
Int 7: 42
|
||||
Int 8: -42
|
||||
Int 9: None
|
||||
Unsigned 1: 42
|
||||
Unsigned 2: 18446744073709551574
|
||||
Unsigned 3: 42
|
||||
Unsigned 4: 42
|
||||
Unsigned 5: 42
|
||||
Unsigned 6: None
|
||||
Real 1: 0.1
|
||||
Real 2: 4.2e-06
|
||||
Real 3: 42.0
|
||||
Real 4: -42.0
|
||||
Real 5: None
|
||||
String 1: 'String without quotes'
|
||||
String 2: '"String with double quotes"'
|
||||
String 3: ''String with single quotes''
|
||||
String 4: '"String concat " "with" ' mixed ' 'quotes' " and so"'
|
||||
String 5: '# not empty'
|
||||
String 6: '"" # not empty too'
|
||||
String 7: '" " # a space, don't know why you'd want that...'
|
||||
String 8: '"Smile! 😀😀😀"'
|
||||
String 9: None
|
||||
Sections:
|
||||
-> section
|
||||
-> booleans
|
||||
-> integers
|
||||
-> unsigneds
|
||||
-> reals
|
||||
-> strings
|
||||
-> section2
|
||||
Variables of [section]:
|
||||
-> ('variable', 'value')
|
||||
-> ('key2', 'value 2')
|
||||
-> ('key3', 'a value with continuation and nothing more')
|
||||
-> ('a_long_key_that_spans_a_whole_lot_of_characters_and_is_practically_useless', 'value4')
|
||||
-> ('number', '0.000001')
|
||||
Variables of all sections:
|
||||
-> ('variable', 'value')
|
||||
-> ('key2', 'value 2')
|
||||
-> ('key3', 'a value with continuation and nothing more')
|
||||
-> ('a_long_key_that_spans_a_whole_lot_of_characters_and_is_practically_useless', 'value4')
|
||||
-> ('number', '0.000001')
|
||||
-> ('bool', 'true')
|
||||
-> ('bool', 'yes')
|
||||
-> ('bool', '1')
|
||||
-> ('bool', 'on')
|
||||
-> ('bool', 'false')
|
||||
-> ('bool', 'no')
|
||||
-> ('bool', '0')
|
||||
-> ('bool', 'off')
|
||||
-> ('bool', 'invalid')
|
||||
-> ('int', '42')
|
||||
-> ('int', '-42')
|
||||
-> ('int', '0x2a')
|
||||
-> ('int', '-0x2a')
|
||||
-> ('int', '0o52')
|
||||
-> ('int', '-0o52')
|
||||
-> ('int', '0b101010')
|
||||
-> ('int', '-0b101010')
|
||||
-> ('int', 'invalid')
|
||||
-> ('unsigned', '42')
|
||||
-> ('unsigned', '-42')
|
||||
-> ('unsigned', '0x2a')
|
||||
-> ('unsigned', '0o52')
|
||||
-> ('unsigned', '0b101010')
|
||||
-> ('unsigned', 'invalid')
|
||||
-> ('real', '0.1')
|
||||
-> ('real', '0.0000042')
|
||||
-> ('real', '42')
|
||||
-> ('real', '-4.2e1')
|
||||
-> ('real', 'invalid')
|
||||
-> ('string', 'String without quotes')
|
||||
-> ('string', '"String with double quotes"')
|
||||
-> ('string', "'String with single quotes'")
|
||||
-> ('string', '"String concat " "with" \' mixed \' \'quotes\' " and so"')
|
||||
-> ('string', '# not empty')
|
||||
-> ('string', '"" # not empty too')
|
||||
-> ('string', '" " # a space, don\'t know why you\'d want that...')
|
||||
-> ('string', '"Smile! 😀😀😀"')
|
||||
-> ('key1', 'value1')
|
||||
-> ('key1', 'value2')
|
||||
-> ('key1', 'value3')
|
||||
-> ('key4', 'value4')
|
||||
Variables of non-existent section: []
|
||||
values.ini:22: [integers]int='42'
|
||||
values.ini:50: [strings]string=''String with single quotes''
|
||||
None:None: [missing]missing=None
|
||||
findall [section2]key1: value1, value2, value3
|
||||
findall [section2]: value1, value2, value3, value4
|
||||
101
tests/inifile/python_bindings/test
Executable file
101
tests/inifile/python_bindings/test
Executable file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import linuxcnc
|
||||
|
||||
ini = linuxcnc.ini("values.ini")
|
||||
|
||||
# Test availability testing
|
||||
if ini.hassection("notasection"):
|
||||
print("Missing section was wrongfully detected")
|
||||
else:
|
||||
print("Missing section was missing")
|
||||
|
||||
if ini.hassection("section"):
|
||||
print("Present section was present")
|
||||
else:
|
||||
print("Present section was wrongfully detected as not present")
|
||||
|
||||
if ini.hasvariable("section", "missing"):
|
||||
print("Missing variable was detected to be present")
|
||||
else:
|
||||
print("Missing variable was missing")
|
||||
|
||||
if ini.hasvariable("section", "variable"):
|
||||
print("Present [section]variable was present")
|
||||
else:
|
||||
print("Present [section]variable was wrongfully detected as not present")
|
||||
|
||||
# Test booleans
|
||||
for n in range(1, 9+1):
|
||||
print("Bool {}: {}".format(n, ini.getbool("booleans", "bool", n)))
|
||||
if True != ini.getbool("booleans", "missing", fallback=True):
|
||||
print("Bool default True failed")
|
||||
if False != ini.getbool("booleans", "missing", fallback=False):
|
||||
print("Bool default False failed")
|
||||
if "hello" != ini.getbool("booleans", "missing", fallback="hello"):
|
||||
print("Bool default 'hello' failed")
|
||||
|
||||
# Test integers
|
||||
for n in range(1, 9+1):
|
||||
print("Int {}: {}".format(n, ini.getsint("integers", "int", n)))
|
||||
if 42 != ini.getsint("integers", "missing", fallback=42):
|
||||
print("Int default 42 failed")
|
||||
if "_42" != ini.getsint("integers", "missing", fallback="_42"): # any fallback type is returned
|
||||
print("Int default '_42' failed")
|
||||
if ini.getsint("integers", "int") != ini.getint("integers", "int"):
|
||||
print("getsint/getint alias error")
|
||||
|
||||
# Test unsigneds
|
||||
for n in range(1, 6+1):
|
||||
print("Unsigned {}: {}".format(n, ini.getuint("unsigneds", "unsigned", n)))
|
||||
if 42 != ini.getuint("unsigneds", "missing", fallback=42):
|
||||
print("Unsigned default 42 failed")
|
||||
if "_42" != ini.getuint("unsigneds", "missing", fallback="_42"): # any fallback type is returned
|
||||
print("Unsigned default '_42' failed")
|
||||
|
||||
# Test reals
|
||||
for n in range(1, 5+1):
|
||||
print("Real {}: {}".format(n, ini.getreal("reals", "real", n)))
|
||||
if 42 != ini.getreal("reals", "missing", fallback=4.2e1):
|
||||
print("Real default 4.2e1 failed")
|
||||
if "_42" != ini.getreal("reals", "missing", fallback="_42"): # any fallback type is returned
|
||||
print("Real default '_42' failed")
|
||||
if ini.getreal("reals", "real") != ini.getfloat("reals", "real"):
|
||||
print("getreal/getfloat alias error")
|
||||
|
||||
# Test strings
|
||||
for n in range(1, 8+1):
|
||||
print("String {}: '{}'".format(n, ini.getstring("strings", "string", n)))
|
||||
# One more to get None back, but we don't want the quotes
|
||||
print("String {}: {}".format(n+1, ini.getstring("strings", "string", n+1)))
|
||||
if None != ini.getstring("strings", "missing"):
|
||||
print("String not found failed")
|
||||
if "|_-42-_|" != ini.getstring("strings", "missing", fallback="|_-42-_|"):
|
||||
print("String default '|_-42-_|' failed")
|
||||
|
||||
# Test sections and variables
|
||||
print("Sections:")
|
||||
for s in ini.getsections():
|
||||
print("-> {}".format(s))
|
||||
print("Variables of [section]:")
|
||||
for v in ini.getvariables("section"):
|
||||
print("-> {}".format(v))
|
||||
print("Variables of all sections:")
|
||||
for v in ini.getvariables():
|
||||
print("-> {}".format(v))
|
||||
print("Variables of non-existent section:", ini.getvariables("not_a_section_we_know_of"))
|
||||
|
||||
# Test find/findall
|
||||
if None != ini.find("section", "missing"):
|
||||
print("find: Missing value was not missing")
|
||||
|
||||
# Test lineof
|
||||
f, l = ini.lineof("integers", "int")
|
||||
print("{}:{}: [integers]int='{}'".format(f, l, ini.getint("integers", "int")))
|
||||
f, l = ini.lineof("strings", "string", 3)
|
||||
print("{}:{}: [strings]string='{}'".format(f, l, ini.getstring("strings", "string", 3)))
|
||||
f, l = ini.lineof("missing", "missing")
|
||||
print("{}:{}: [missing]missing={}".format(f, l, ini.getstring("missing", "missing")))
|
||||
|
||||
print("findall [section2]key1:", ", ".join(ini.findall("section2", "key1")))
|
||||
print("findall [section2]:", ", ".join(ini.findall("section2", "")))
|
||||
61
tests/inifile/python_bindings/values.ini
Normal file
61
tests/inifile/python_bindings/values.ini
Normal file
@@ -0,0 +1,61 @@
|
||||
[section]
|
||||
variable=value
|
||||
key2=value 2
|
||||
key3 = a value \
|
||||
with continuation \
|
||||
and nothing more
|
||||
a_long_key_that_spans_a_whole_lot_of_characters_and_is_practically_useless = value4
|
||||
number = 0.000001
|
||||
|
||||
[booleans]
|
||||
bool = true
|
||||
bool = yes
|
||||
bool = 1
|
||||
bool = on
|
||||
bool = false
|
||||
bool = no
|
||||
bool = 0
|
||||
bool = off
|
||||
bool = invalid
|
||||
|
||||
[integers]
|
||||
int = 42
|
||||
int = -42
|
||||
int = 0x2a
|
||||
int = -0x2a
|
||||
int = 0o52
|
||||
int = -0o52
|
||||
int = 0b101010
|
||||
int = -0b101010
|
||||
int = invalid
|
||||
|
||||
[unsigneds]
|
||||
unsigned = 42
|
||||
unsigned = -42
|
||||
unsigned = 0x2a
|
||||
unsigned = 0o52
|
||||
unsigned = 0b101010
|
||||
unsigned = invalid
|
||||
|
||||
[reals]
|
||||
real = 0.1
|
||||
real = 0.0000042
|
||||
real = 42
|
||||
real = -4.2e1
|
||||
real = invalid
|
||||
|
||||
[strings]
|
||||
string = String without quotes
|
||||
string = "String with double quotes"
|
||||
string = 'String with single quotes'
|
||||
string = "String concat " "with" ' mixed ' 'quotes' " and so"
|
||||
string = # not empty
|
||||
string = "" # not empty too
|
||||
string = " " # a space, don't know why you'd want that...
|
||||
string = "Smile! \U0001F600\ud83d\ude00\xf0\x9f\x98\x80"
|
||||
|
||||
[section2]
|
||||
key1=value1
|
||||
key1=value2
|
||||
key1=value3
|
||||
key4=value4
|
||||
Reference in New Issue
Block a user