Restructure project directory, python files are now in their own folder
This commit is contained in:
		
							
								
								
									
										0
									
								
								python/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								python/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										27
									
								
								python/tests/test_editor.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								python/tests/test_editor.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
"""
 | 
			
		||||
.. moduleauthor:: Eric Torres
 | 
			
		||||
 | 
			
		||||
Tests for the rbackup.config module.
 | 
			
		||||
"""
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
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_override(self):
 | 
			
		||||
        override = "doesnotexist"
 | 
			
		||||
        with self.assertRaises(FileNotFoundError):
 | 
			
		||||
            editor.select_editor(override)
 | 
			
		||||
							
								
								
									
										50
									
								
								python/tests/test_fzf.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								python/tests/test_fzf.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
"""
 | 
			
		||||
.. 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()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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.side_effect = subprocess.CalledProcessError(1, "hi")
 | 
			
		||||
 | 
			
		||||
        with self.assertRaises(fzf.FZFError):
 | 
			
		||||
            fzf.select_file_with_fzf(b"test")
 | 
			
		||||
 | 
			
		||||
    def tearDown(self):
 | 
			
		||||
        patch.stopall()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestFZFErrorClass(unittest.TestCase):
 | 
			
		||||
    def test_class_repr(self):
 | 
			
		||||
        f = fzf.FZFError(1, "error")
 | 
			
		||||
        f
 | 
			
		||||
        str(f)
 | 
			
		||||
							
								
								
									
										90
									
								
								python/tests/test_search.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								python/tests/test_search.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
"""
 | 
			
		||||
.. moduleauthor:: Eric Torres
 | 
			
		||||
 | 
			
		||||
Tests for the rbackup.config module.
 | 
			
		||||
"""
 | 
			
		||||
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
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # bin, opts, pattern, directory
 | 
			
		||||
 | 
			
		||||
    @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 = "path/to/find"
 | 
			
		||||
        test_opts = ["option1", "option2"]
 | 
			
		||||
        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_run = self.patched_subprocess.start()
 | 
			
		||||
 | 
			
		||||
        search.LOCATE_OPTS = ["opt1", "opt2"]
 | 
			
		||||
 | 
			
		||||
    @given(test_patterns=lists(text()), bin=text())
 | 
			
		||||
    def test_bin_override(self, test_patterns, bin):
 | 
			
		||||
        search.locate_files(test_patterns, bin_override=bin)
 | 
			
		||||
        self.mocked_run.assert_called_with(
 | 
			
		||||
            [bin, *search.LOCATE_OPTS, "--", *test_patterns],
 | 
			
		||||
            capture_output=True,
 | 
			
		||||
            text=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def tearDown(self):
 | 
			
		||||
        patch.stopall()
 | 
			
		||||
		Reference in New Issue
	
	Block a user