file-scripts/tests/test_fzf.py

46 lines
1.2 KiB
Python
Raw Normal View History

2020-10-23 11:21:59 -07:00
"""
.. moduleauthor:: Eric Torres
:synopsis: Unit tests for the fzf module.
"""
import subprocess
import unittest
from pathlib import Path
from unittest.mock import patch
import file_scripts.fzf as fzf
# ========== Constants ==========
TESTING_PACKAGE = "file_scripts"
TESTING_MODULE = f"{TESTING_PACKAGE}.fzf"
# ========== Test Cases ==========
class TestRunFZF(unittest.TestCase):
def setUp(self):
self.patched_subprocess = patch(f"{TESTING_MODULE}.subprocess.run")
self.mocked_run = self.patched_subprocess.start()
def test_creates_pathlike_object(self):
2021-12-20 22:43:18 -08:00
self.assertIsInstance(fzf.select_file_with_fzf(b"test"), Path)
2020-10-23 11:21:59 -07:00
def tearDown(self):
patch.stopall()
class TestFZFErrors(unittest.TestCase):
def setUp(self):
self.patched_subprocess = patch(f"{TESTING_MODULE}.subprocess.run")
self.mocked_run = self.patched_subprocess.start()
def test_raises_error(self):
self.mocked_run.return_value.check_returncode.side_effect = (
subprocess.CalledProcessError(1, "hi")
)
with self.assertRaises(fzf.FZFError):
fzf.select_file_with_fzf(b"test")
def tearDown(self):
patch.stopall()