util: + Symbol and keywords stuff (with tests)
This commit is contained in:
parent
afe858fc9f
commit
f0745f4a7b
2 changed files with 30 additions and 0 deletions
|
|
@ -5,6 +5,23 @@ import hashlib
|
|||
from secrets import choice
|
||||
import string
|
||||
|
||||
# symbols and keywords
|
||||
|
||||
class Symbol(str):
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Symbol "{self}">'
|
||||
|
||||
class Symbols:
|
||||
|
||||
def __getattr__(self, k):
|
||||
sym = Symbol(k)
|
||||
setattr(self, k, sym)
|
||||
return sym
|
||||
|
||||
keywords = Symbols()
|
||||
|
||||
|
||||
# random strings, hashes, encodings
|
||||
# for authentication, encryption, and other purposes
|
||||
|
||||
|
|
|
|||
13
tests/test_util.py
Normal file
13
tests/test_util.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# py-scopes: tests.test_util
|
||||
|
||||
"""Tests for scopes.util package"""
|
||||
|
||||
import pytest
|
||||
|
||||
from scopes.util import keywords as k
|
||||
|
||||
def test_keywords():
|
||||
assert k.dummy is k.dummy
|
||||
assert k.dummy is not k.other
|
||||
assert getattr(k, "abcd"[-2:]) is k.cd
|
||||
|
||||
Loading…
Add table
Reference in a new issue