Skip to content

Commit

Permalink
pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
JavanW-W committed Oct 23, 2023
1 parent 1200dc7 commit 57c8bcd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
mypy copley
- name: Pytest
run: |
pytest copley
pytest tests
37 changes: 22 additions & 15 deletions copley/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,29 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.hw = AsyncClientMock()

async def _parse(self, command):
"""Return mock requests to parsing."""
async def query(self, command):
"""Return mock requests to query."""
if not self.lock:
self.lock = asyncio.Lock()
async with self.lock: # lock releases on CancelledError
if command == self.PRINT_REPORT:
return {
'serial_number': 12345,
'calc_type': "Fixed weight",
'set_speed': "300",
'total_taps': 1250,
'sample_weight': "2.77",
'init_volume': "170.0",
'final_volume': "155.0",
'bulk_density': "0.016",
'tapped_density': "0.018",
'hausner_ratio': "1.097",
'compress_index': "8.82"
}
return 'hello world :)'

def _parse(self, response):
"""Return mock requests to parsing."""
if response is None:
return {'on': False}
else:
return {
'serial_number': 12345,
'calc_type': "Fixed weight",
'set_speed': "300",
'total_taps': 1250,
'sample_weight': "2.77",
'init_volume': "170.0",
'final_volume': "155.0",
'bulk_density': "0.016",
'tapped_density': "0.018",
'hausner_ratio': "1.097",
'compress_index': "8.82"
}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_ignore = D104,D107

[tool:pytest]
asyncio_mode = auto
addopts = --cov=ika
addopts = --cov=copley

[tool:ruff]
target-version = "py38"
Expand Down
1 change: 0 additions & 1 deletion tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def driver():
return TapDensity(ADDRESS)


@mock.patch('copley.TapDensity.query')
@mock.patch('copley.TapDensity', TapDensity)
def test_driver_cli(capsys):
"""Confirm the commandline interface works."""
Expand Down

0 comments on commit 57c8bcd

Please sign in to comment.