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()
|
2021-12-29 23:31:08 -08:00
|
|
|
|
|
|
|
|
|
|
|
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()
|