Initial commit
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
29
tests/test_editor.py
Normal file
29
tests/test_editor.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""
|
||||
.. moduleauthor:: Eric Torres
|
||||
|
||||
Tests for the rbackup.config module.
|
||||
"""
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import file_scripts.editor as editor
|
||||
|
||||
# ========== Constants ==========
|
||||
# ========== Tests ==========
|
||||
|
||||
"""Test the select_editor() function.
|
||||
|
||||
Test cases
|
||||
-----------
|
||||
* Returned object is an instance of str
|
||||
* If override is not None, ensure that it is in the result
|
||||
|
||||
"""
|
||||
class TestSelectEditor(unittest.TestCase):
|
||||
def test_returns_path_object(self):
|
||||
self.assertIsInstance(editor.select_editor(), str)
|
||||
|
||||
def test_override(self):
|
||||
override = "doesnotexist"
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
editor.select_editor(override)
|
27
tests/test_fzf.py
Normal file
27
tests/test_fzf.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""
|
||||
.. 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):
|
||||
self.assertIsInstance(fzf.select_file_with_fzf(b'test'), Path)
|
||||
|
||||
def tearDown(self):
|
||||
patch.stopall()
|
90
tests/test_search.py
Normal file
90
tests/test_search.py
Normal file
@ -0,0 +1,90 @@
|
||||
"""
|
||||
.. moduleauthor:: Eric Torres
|
||||
|
||||
Tests for the rbackup.config module.
|
||||
"""
|
||||
import subprocess
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from hypothesis import given
|
||||
from hypothesis.strategies import text, lists
|
||||
|
||||
import file_scripts.search as search
|
||||
|
||||
# ========== Constants ==========
|
||||
TESTING_PACKAGE = "file_scripts"
|
||||
TESTING_MODULE = f"{TESTING_PACKAGE}.search"
|
||||
|
||||
# ========== Tests ==========
|
||||
"""Test the find_files() function.
|
||||
|
||||
Test cases
|
||||
-----------
|
||||
* Both cases of capture_text
|
||||
* bin_override behaves correctly
|
||||
* directory is not None
|
||||
"""
|
||||
|
||||
|
||||
class TestFindFiles(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.patched_subprocess = patch(f"{TESTING_MODULE}.subprocess.run")
|
||||
|
||||
self.mocked_run = self.patched_subprocess.start()
|
||||
|
||||
@given(test_override=text(), test_opts=lists(text()))
|
||||
def test_bin_override(self, test_override, test_opts):
|
||||
search.find_files(opts=test_opts, bin_override=test_override)
|
||||
self.mocked_run.assert_called_with(
|
||||
[test_override, *test_opts], capture_output=True, text=None
|
||||
)
|
||||
|
||||
@given(text())
|
||||
def test_directory_override(self, d):
|
||||
test_override = "fd_bin"
|
||||
test_opts = ["option1", "option2"]
|
||||
expected_dir_options = ["--", ".", d]
|
||||
search.find_files(opts=test_opts, directory=d, bin_override=test_override)
|
||||
self.mocked_run.assert_called_with(
|
||||
[test_override, *test_opts, *expected_dir_options],
|
||||
capture_output=True,
|
||||
text=None,
|
||||
)
|
||||
|
||||
def test_default_directory(self):
|
||||
test_override = "fd_bin"
|
||||
test_opts = ["option1"]
|
||||
expected_cmd = [test_override, *test_opts]
|
||||
search.find_files(opts=test_opts, bin_override=test_override)
|
||||
self.mocked_run.assert_called_with(expected_cmd, capture_output=True, text=None)
|
||||
|
||||
def tearDown(self):
|
||||
patch.stopall()
|
||||
|
||||
|
||||
"""Test search.locate_files()
|
||||
"""
|
||||
|
||||
|
||||
class LocateFiles(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.patched_locate_opts = patch(f"{TESTING_MODULE}")
|
||||
self.patched_subprocess = patch(f"{TESTING_MODULE}.subprocess.run")
|
||||
|
||||
self.mocked_locate_opts = self.patched_subprocess.start()
|
||||
self.mocked_run = self.patched_subprocess.start()
|
||||
|
||||
self.mocked_locate_opts.LOCATE_OPTS = ["opt1", "opt2"]
|
||||
|
||||
@given(p=lists(text()), b=text())
|
||||
def test_bin_override(self, p, b):
|
||||
search.locate_files(p, bin_override=b)
|
||||
self.mocked_run.assert_called_with(
|
||||
[b, *self.mocked_locate_opts, *p],
|
||||
capture_output=True,
|
||||
text=None,
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
patch.stopall()
|
Reference in New Issue
Block a user