Skip to content

Commit

Permalink
sorted imports, and pytest skip because I can't get runpy.run_path wo…
Browse files Browse the repository at this point in the history
…rking with mock.spy
  • Loading branch information
langnostic committed Aug 3, 2021
1 parent cf2f565 commit 11b1372
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"python.linting.enabled": true,
"editor.formatOnSave": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false
"python.testing.nosetestsEnabled": false,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
}
}
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ allow_prereleases = true

[scripts]
click = "./click"
test = "pytest -v --cov=clicker --capture=sys tests/"
tests = "pytest -v --cov=clicker --capture=sys tests/"
test = "python -m pytest -v --cov=clicker --capture=sys tests/"
tests = "python -m pytest -v --cov=clicker --capture=sys tests/"
clean = "rm -rf htmlcov/ .coverage .pytest_cache clicker/__pycache__/ test/__pycache__"
cover = "bash coverage.sh"
5 changes: 2 additions & 3 deletions clicker/clicker.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Auto Mouse Clicker Script. Make it look like your still online with Python Automation."""

from typing import Optional
from time import sleep
from random import randint
from time import sleep
from typing import Optional

import pyautogui
import typer


# Disable FailSafeException when mouse is in screen corners.
# I don't need a failsafe for this script.
pyautogui.FAILSAFE = False
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auto_click.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clicker

from pytest_mock import MockerFixture
from pytest import CaptureFixture
from pytest_mock import MockerFixture


# using pytest-mock for easier function mocking
def test_click_works(mocker: MockerFixture) -> None:
Expand Down
1 change: 0 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import clicker

from pytest import CaptureFixture
from pytest_mock import MockerFixture

Expand Down
22 changes: 19 additions & 3 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import clicker
import runpy

import clicker
import pytest
from pytest_mock import MockerFixture
import runpy


def test_run_method(mocker: MockerFixture) -> None:
Expand All @@ -15,15 +16,30 @@ def test_run_method(mocker: MockerFixture) -> None:
mock_typer.assert_called_once_with(clicker.clicker._main)


# use runpy to run python script like an actual script or module
def test___main__py(mocker: MockerFixture) -> None:
# Arrange
mock_typer = mocker.patch("clicker.clicker.typer.run")
spy_run = mocker.spy(clicker, "run")

# Act
# use runpy to run python script like an actual script or modules
runpy.run_module("clicker", run_name="__main__")

# Assert
mock_typer.assert_called_once_with(clicker.clicker._main)
spy_run.assert_called_once()


@pytest.mark.skip(reason="Can't figure out how to call file __main__ block.")
def test__name_equals__main_clicker(mocker: MockerFixture) -> None:
# Arrange
spy_run = mocker.spy(clicker, "run")
mock_typer = mocker.patch("clicker.clicker.typer.run")
mocker.resetall()
# Act
# runpy.run_module("clicker", run_name="__main__")
runpy.run_module("clicker.clicker", run_name="__main__")

# Assert
mock_typer.assert_called_once_with(clicker.clicker._main)
spy_run.assert_called_once()

0 comments on commit 11b1372

Please sign in to comment.