Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewReid854 committed Apr 3, 2021
1 parent 41bb7cf commit f85151e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
5 changes: 2 additions & 3 deletions check4updates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ def __init__(
check_and_prompt.printred("3. Skip this version")
check_and_prompt.printred("4. Never ask me again")
if mock_user_input is None:
red, endred = "\033[91m", "\033[0m"
prompt_choice = input(
str(red + "Your choice: " + endred)
)
str("\033[91m" + "Your choice: " + "\033[0m")
) # the special characters are to make the text red
else:
# accept the mocked user input
prompt_choice = mock_user_input
Expand Down
30 changes: 25 additions & 5 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import requests
import pytest
import time

def cleanup(package_name):
cwd = os.getcwd()
Expand All @@ -15,45 +16,64 @@ def cleanup(package_name):
pass
os.chdir(path=cwd) # reset the current working directory

def test_packagename_not_str():
def test_packagename_not_str1():
with pytest.raises(ValueError):
check_and_prompt(package_name=True)

def test_packagename_not_str2():
with pytest.raises(ValueError):
upgrade(package_name=True)

def test_choice_upgrade():
package_name = 'numpy'
cleanup(package_name)
check_and_prompt(package_name, mock_user_input='1') # writes the new file
result = check_and_prompt(package_name, mock_user_input='1') # reads the file
result = check_and_prompt(package_name) # reads the file
assert result.action == 'remind'
cleanup(package_name)

def test_choice_remind():
package_name = 'numpy'
cleanup(package_name)
check_and_prompt(package_name, mock_user_input='2') # writes the new file
result = check_and_prompt(package_name, mock_user_input='2') # reads the file
result = check_and_prompt(package_name) # reads the file
assert result.action == 'remind'
cleanup(package_name)

def test_choice_remind_timecheck():
package_name = 'numpy'
cleanup(package_name)
check_and_prompt(package_name, mock_user_input='2') # writes the new file
time.sleep(0.2) # 0.2 seconds pause so we will be reminded
check_and_prompt(package_name, mock_user_input='3', remind_delay=0.1) # reads the file
result = check_and_prompt(package_name) # reads the file
assert result.action == 'skip'
cleanup(package_name)

def test_choice_skip():
package_name = 'numpy'
cleanup(package_name)
check_and_prompt(package_name, mock_user_input='3') # writes the new file
result = check_and_prompt(package_name, mock_user_input='3') # reads the file
result = check_and_prompt(package_name) # reads the file
assert result.action == 'skip'
check_and_prompt(package_name) #this should not prompt the user as skip was already specified
assert result.action == 'skip'
cleanup(package_name)

def test_choice_neveragain():
package_name = 'numpy'
cleanup(package_name)
check_and_prompt(package_name, mock_user_input='4') # writes the new file
result = check_and_prompt(package_name, mock_user_input='4') # reads the file
result = check_and_prompt(package_name) # reads the file
assert result.action == 'neveragain'
cleanup(package_name)

def test_upgrade():
package_name = 'seaborn' # this is used as a test case on GitHub actions which does not have seaborn installed when the VM starts
out = upgrade(package_name)
assert out.success == True
check_and_prompt(package_name) # this should write the new file and not prompt the user as seaborn is already upgraded
result = check_and_prompt(package_name) # reads the file
assert result.action == 'checked'


0 comments on commit f85151e

Please sign in to comment.