mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-06-08 19:59:56 +02:00
counter: init-overrideable
This commit is contained in:
parent
9b1da7c023
commit
98568402c7
2 changed files with 29 additions and 0 deletions
|
@ -7,6 +7,8 @@ class EynollahIdCounter():
|
||||||
|
|
||||||
def __init__(self, region_idx=0, line_idx=0):
|
def __init__(self, region_idx=0, line_idx=0):
|
||||||
self._counter = Counter()
|
self._counter = Counter()
|
||||||
|
self.set('region', region_idx)
|
||||||
|
self.set('line', line_idx)
|
||||||
|
|
||||||
def inc(self, name, val=1):
|
def inc(self, name, val=1):
|
||||||
self._counter.update({name: val})
|
self._counter.update({name: val})
|
||||||
|
|
27
tests/test_counter.py
Normal file
27
tests/test_counter.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from tests.base import main
|
||||||
|
from qurator.eynollah.utils.counter import EynollahIdCounter
|
||||||
|
|
||||||
|
def test_counter_string():
|
||||||
|
c = EynollahIdCounter()
|
||||||
|
assert c.next_region_id == 'region_0001'
|
||||||
|
assert c.next_region_id == 'region_0002'
|
||||||
|
assert c.next_line_id == 'region_0002_line_0001'
|
||||||
|
assert c.next_region_id == 'region_0003'
|
||||||
|
assert c.next_line_id == 'region_0003_line_0001'
|
||||||
|
|
||||||
|
def test_counter_init():
|
||||||
|
c = EynollahIdCounter(region_idx=2)
|
||||||
|
assert c.get('region') == 2
|
||||||
|
|
||||||
|
def test_counter_methods():
|
||||||
|
c = EynollahIdCounter()
|
||||||
|
assert c.get('region') == 0
|
||||||
|
c.inc('region', 5)
|
||||||
|
assert c.get('region') == 5
|
||||||
|
c.set('region', 10)
|
||||||
|
assert c.get('region') == 10
|
||||||
|
c.inc('region', -9)
|
||||||
|
assert c.get('region') == 1
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(__file__)
|
Loading…
Add table
Add a link
Reference in a new issue