b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | [ "$1" = python3-constantly ] || exit 0 |
| 4 | |
| 5 | python3 - << 'EOF' |
| 6 | |
| 7 | from constantly import NamedConstant, Names |
| 8 | class Letters(Names): |
| 9 | a = NamedConstant() |
| 10 | b = NamedConstant() |
| 11 | c = NamedConstant() |
| 12 | |
| 13 | assert Letters.lookupByName('a') is Letters.a |
| 14 | assert Letters.a < Letters.b |
| 15 | assert Letters.b < Letters.c |
| 16 | assert Letters.a < Letters.c |
| 17 | |
| 18 | from constantly import ValueConstant, Values |
| 19 | class STATUS(Values): |
| 20 | OK = ValueConstant('200') |
| 21 | FOUND = ValueConstant('302') |
| 22 | NOT_FOUND = ValueConstant('404') |
| 23 | |
| 24 | assert STATUS.OK.value == '200' |
| 25 | assert STATUS.lookupByValue('404') == STATUS.NOT_FOUND |
| 26 | |
| 27 | EOF |