suou/tests/test_strtools.py

40 lines
1,005 B
Python
Raw Normal View History

2025-07-19 11:31:01 +02:00
import unittest
from suou.strtools import PrefixIdentifier
from pydantic import ValidationError
2025-07-19 11:31:01 +02:00
class TestStrtools(unittest.TestCase):
def setUp(self) -> None:
...
def tearDown(self) -> None:
...
def test_PrefixIdentifier_empty(self):
pi = PrefixIdentifier(None)
self.assertEqual(pi.hello, 'hello')
self.assertEqual(pi['with spaces'], 'with spaces')
self.assertEqual(pi['\x1b\x00'], '\x1b\0')
self.assertEqual(pi.same_thing, pi['same_thing'])
with self.assertRaises(ValidationError):
2025-07-19 11:31:01 +02:00
pi[0]
self.assertEqual(f'{PrefixIdentifier(None)}', f'{PrefixIdentifier("")}')
2025-07-19 11:31:01 +02:00
def test_PrefixIdentifier_get_nostr(self):
2025-07-19 11:31:01 +02:00
with self.assertRaises(TypeError):
pi = PrefixIdentifier(1)
pi.hello
with self.assertRaises(TypeError):
PrefixIdentifier([99182])
with self.assertRaises(TypeError):
PrefixIdentifier(b'alpha_')