Portal/rsconcept/backend/apps/rsform/tests/t_utils.py
IRBorisov 2759f10d09
Some checks failed
Backend CI / build (3.12) (push) Has been cancelled
Frontend CI / build (18.x) (push) Has been cancelled
Initial commit
2024-06-07 20:17:03 +03:00

26 lines
1.0 KiB
Python

''' Unit tests: utils. '''
import re
import unittest
from apps.rsform.utils import apply_pattern, fix_old_references
class TestUtils(unittest.TestCase):
''' Test various utility functions. '''
def test_apply_mapping_patter(self):
mapping = {'X101': 'X20'}
pattern = re.compile(r'(X[0-9]+)')
self.assertEqual(apply_pattern('', mapping, pattern), '')
self.assertEqual(apply_pattern('X20', mapping, pattern), 'X20')
self.assertEqual(apply_pattern('X101', mapping, pattern), 'X20')
self.assertEqual(apply_pattern('asdf X101 asdf', mapping, pattern), 'asdf X20 asdf')
def test_fix_old_references(self):
self.assertEqual(fix_old_references(''), '')
self.assertEqual(fix_old_references('X20'), 'X20')
self.assertEqual(fix_old_references('@{X1|nomn,sing}'), '@{X1|nomn,sing}')
self.assertEqual(fix_old_references('@{X1|sing,ablt} @{X1|sing,ablt}'), '@{X1|sing,ablt} @{X1|sing,ablt}')
self.assertEqual(fix_old_references('@{X1|nomn|sing}'), '@{X1|nomn,sing}')