1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 15:57:14 +03:00

checked negatives, added test to that effect

This commit is contained in:
A_D 2021-08-11 17:06:01 +02:00
parent 1c3c29abb6
commit 3133cba0a4
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4
2 changed files with 7 additions and 3 deletions

View File

@ -81,8 +81,9 @@ def _apply(target: UPDATABLE_DATA, key: str, to_set: Any = None, delete: bool =
if idx is None:
raise ValueError(f'Cannot use string {key!r} as int for index into Sequence')
if delete:
if len(target) > idx:
if delete and len(target) > 0:
length = len(target)
if (idx > 0 and length > idx) or idx >= -length:
target.pop(idx)
elif len(target) == idx:

View File

@ -15,7 +15,10 @@ from killswitch import UPDATABLE_DATA
(['this', 'is', 'a', 'test'], '1', '', None, ['this', None, 'a', 'test']),
({'now': 'with', 'a': 'dict'}, 'now', 'delete', None, {'a': 'dict'}),
({'now': 'with', 'a': 'dict'}, 'now', '', None, {'now': None, 'a': 'dict'}),
(['test append'], '1', '', 'yay', ['test append', 'yay'])
(['test append'], '1', '', 'yay', ['test append', 'yay']),
(['test neg del'], '-1', 'delete', None, []),
(['test neg del'], '-1337', 'delete', None, ['test neg del']),
(['test neg del'], '-2', 'delete', None, ['test neg del']),
]
)
def test_apply(source: UPDATABLE_DATA, key: str, action: str, to_set: Any, result: UPDATABLE_DATA) -> None: