Skip to content

Commit

Permalink
Update tests\
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Aug 15, 2022
1 parent e3834f8 commit 26e3744
Show file tree
Hide file tree
Showing 10 changed files with 677 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ venv/
.ipynb_checkpoints
*/.ipynb_checkpoints/*

# Testing
# Unit test / coverage reports
htmlcov/
.coverage
.coverage.*
coverage.xml
.pytest_cache/

# PyHelpers
Expand All @@ -22,4 +26,5 @@ tests/*
!tests/data/
!tests/documents/
!tests/images/
!tests/*.py
.pypirc
1 change: 1 addition & 0 deletions pyhelpers/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ def merge_dicts(*dicts):
>>> dict_1 = merged_dict
>>> dict_2 = {'b': 2, 'c': 4, 'd': [5, 6]}
>>> merged_dict = merge_dicts(dict_1, dict_2)
>>> merged_dict
{'a': 1, 'b': 2, 'c': [[3, 4], 4], 'd': [5, 6]}
"""

Expand Down
Empty file added tests/__init__.py
Empty file.
Binary file modified tests/data/csr_mat.npz
Binary file not shown.
Binary file modified tests/data/dat.feather
Binary file not shown.
Binary file modified tests/data/dat.xlsx
Binary file not shown.
36 changes: 18 additions & 18 deletions tests/images/store-save_fig-demo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Test ops.py"""

import datetime

import pytest


def test_eval_dtype(capfd):
from pyhelpers.ops import eval_dtype

val_1 = '1'
origin_val = eval_dtype(val_1)
assert origin_val == 1

val_2 = '1.1.1'
origin_val = eval_dtype(val_2)
assert origin_val == '1.1.1'


def test_gps_to_utc():
from pyhelpers.ops import gps_to_utc

utc_dt = gps_to_utc(gps_time=1271398985.7822514)

assert utc_dt == datetime.datetime(2020, 4, 20, 6, 23, 5, 782251)


def test_parse_size():
from pyhelpers.ops import parse_size

assert parse_size(size='123.45 MB') == 129446707
assert parse_size(size='123.45 MB', binary=False) == 123450000
assert parse_size(size='123.45 MiB', binary=True) == 129446707
assert parse_size(size='123.45 MiB', binary=False) == 129446707
assert parse_size(size=129446707, precision=2) == '123.45 MiB'
assert parse_size(size=129446707, binary=False, precision=2) == '129.45 MB'


def test_update_dict_keys():
from pyhelpers.ops import update_dict_keys

source_dict = {'a': 1, 'b': 2, 'c': 3}

upd_dict = update_dict_keys(source_dict, replacements=None)
assert upd_dict == {'a': 1, 'b': 2, 'c': 3}

repl_keys = {'a': 'd', 'c': 'e'}
upd_dict = update_dict_keys(source_dict, replacements=repl_keys)
assert upd_dict == {'d': 1, 'b': 2, 'e': 3}

source_dict = {'a': 1, 'b': 2, 'c': {'d': 3, 'e': {'f': 4, 'g': 5}}}

repl_keys = {'d': 3, 'f': 4}
upd_dict = update_dict_keys(source_dict, replacements=repl_keys)
assert upd_dict == {'a': 1, 'b': 2, 'c': {3: 3, 'e': {4: 4, 'g': 5}}}


def test_merge_dicts():
from pyhelpers.ops import merge_dicts

dict_a = {'a': 1}
dict_b = {'b': 2}
dict_c = {'c': 3}

merged_dict = merge_dicts(dict_a, dict_b, dict_c)
assert merged_dict == {'a': 1, 'b': 2, 'c': 3}

dict_c_ = {'c': 4}
merged_dict = merge_dicts(merged_dict, dict_c_)
assert merged_dict == {'a': 1, 'b': 2, 'c': [3, 4]}

dict_1 = merged_dict
dict_2 = {'b': 2, 'c': 4, 'd': [5, 6]}
merged_dict = merge_dicts(dict_1, dict_2)
assert merged_dict == {'a': 1, 'b': 2, 'c': [[3, 4], 4], 'd': [5, 6]}


if __name__ == '__main__':
pytest.main()
Loading

0 comments on commit 26e3744

Please sign in to comment.