Skip to content

Commit

Permalink
refactor test names, add test for low file warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorSheehan1 committed Dec 7, 2020
1 parent 3764160 commit 4c07cd1
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions tests/test_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_version(self):
@patch("glob.glob")
@patch("shutil.copy")
@patch("subprocess.check_output")
def test_shot_default_args(self, check_output_mock, copy_mock, glob_mock):
def test_default_args(self, check_output_mock, copy_mock, glob_mock):
"""
should copy the latest screenshot to the current directory
"""
Expand All @@ -48,7 +48,7 @@ def test_shot_default_args(self, check_output_mock, copy_mock, glob_mock):

@patch("glob.glob")
@patch("subprocess.check_output")
def test_shot_dry_run(self, check_output_mock, glob_mock):
def test_dry_run(self, check_output_mock, glob_mock):
"""
should show the command that would copy the latest screenshot to the current directory
"""
Expand All @@ -61,22 +61,22 @@ def test_shot_dry_run(self, check_output_mock, glob_mock):
check_output_mock.assert_has_calls(check_output_calls)

@patch("glob.glob")
def test_shot_src(self, glob_mock):
def test_src(self, glob_mock):
glob_mock.side_effect = [["/tmp/some/other/path"]]

assert shot(src="/tmp/some/other/path", dry_run=True) == "cp /tmp/some/other/path ."

@patch("glob.glob")
@patch("subprocess.check_output")
def test_shot_dst(self, check_output_mock, glob_mock):
def test_dst(self, check_output_mock, glob_mock):
check_output_mock.side_effect = [b"/tmp/tests\n"]
glob_mock.side_effect = [["/tmp/tests/first"]]

assert shot(dst="/tmp/output", dry_run=True) == "cp /tmp/tests/first /tmp/output"

@patch("glob.glob")
@patch("subprocess.check_output")
def test_shot_move_dry_run(self, check_output_mock, glob_mock):
def test_move_dry_run(self, check_output_mock, glob_mock):
check_output_mock.side_effect = [b"/tmp/tests\n"]
glob_mock.side_effect = [["/tmp/tests/first"]]

Expand All @@ -85,7 +85,7 @@ def test_shot_move_dry_run(self, check_output_mock, glob_mock):
@patch("glob.glob")
@patch("shutil.move")
@patch("subprocess.check_output")
def test_shot_move(self, check_output_mock, move_mock, glob_mock):
def test_move(self, check_output_mock, move_mock, glob_mock):
"""
should move the latest screenshot to the current directory
"""
Expand All @@ -104,7 +104,7 @@ def test_shot_move(self, check_output_mock, move_mock, glob_mock):

@patch("glob.glob")
@patch("subprocess.check_output")
def test_shot_no_files(self, check_output_mock, glob_mock):
def test_no_files(self, check_output_mock, glob_mock):
"""
should warn the user no files were found
"""
Expand All @@ -113,10 +113,34 @@ def test_shot_no_files(self, check_output_mock, glob_mock):

assert shot(color=False) == "No files found in /tmp/tests/empty"

@patch("builtins.print") # note print interferes with termcolor somehow, use color=False
@patch("glob.glob")
@patch("shutil.copy")
@patch("subprocess.check_output")
def test_shot_s_and_n(self, check_output_mock, copy_mock, glob_mock):
def test_not_enough_files(self, check_output_mock, copy_mock, glob_mock, print_mock):
"""
should warn the user there are not enough files, but still copy the ones available
"""
check_output_mock.side_effect = [b"/tmp/tests\n"]
glob_mock.side_effect = [["/tmp/tests/1"]]

check_output_calls = [call(["defaults", "read", "com.apple.screencapture", "location"])]
copy_mock_calls = [call("/tmp/tests/1", ".")]
print_mock_calls = [
call(colored("Warning: there are not enough files to copy with s:0, n:1", "yellow"))
]

assert (
shot(n=2, color=False)
== "Copied the following files to . successfully!\n['/tmp/tests/1']"
)
check_output_mock.assert_has_calls(check_output_calls)
copy_mock.assert_has_calls(copy_mock_calls)

@patch("glob.glob")
@patch("shutil.copy")
@patch("subprocess.check_output")
def test_s_and_n(self, check_output_mock, copy_mock, glob_mock):
"""
should copy the 2 latest screenshots, starting from the 2nd latest
"""
Expand Down

0 comments on commit 4c07cd1

Please sign in to comment.