Skip to content

Commit

Permalink
Merge pull request #4 from bpepple/fix-recursive-filelist
Browse files Browse the repository at this point in the history
Fix get_resursive_filelist(). Fixed #3
  • Loading branch information
bpepple authored Jan 8, 2020
2 parents 501a77f + 9cc76af commit 5993bfd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
8 changes: 6 additions & 2 deletions darkseid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ def get_recursive_filelist(pathlist):
""" Create a recursive list of comic files """
filelist = []
for path in pathlist:
for filename in pathlib.Path(path).rglob("*.[cC][bB][zZ]"):
filelist.append(filename)
path = pathlib.Path(path)
if path.is_dir():
for filename in path.rglob("*.[cC][bB][zZ]"):
filelist.append(filename)
else:
filelist.append(path)

filelist = sorted(filelist)

Expand Down
44 changes: 39 additions & 5 deletions tests/test_darkseid_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import os
import tempfile
import unittest
from pathlib import Path

from darkseid import utils


class TestUtils(unittest.TestCase):
def setUp(self):
self.tmp_dir = tempfile.TemporaryDirectory()
self.tmp_file_1 = tempfile.NamedTemporaryFile(
suffix=".cbz", dir=self.tmp_dir.name
)
self.tmp_file_2 = tempfile.NamedTemporaryFile(
suffix=".cbz", dir=self.tmp_dir.name
)

def tearDown(self):
self.tmp_file_1.close()
self.tmp_file_2.close()
self.tmp_dir.cleanup()

def test_remove_articles(self):
txt = "The Champions & Inhumans"
new_txt = utils.removearticles(txt)
Expand All @@ -19,16 +34,35 @@ def test_list_to_string(self):
self.assertEqual(list_string, expected_result)

def test_unique_name(self):
tmp_file = tempfile.NamedTemporaryFile(suffix=".cbz")
new_file = tmp_file.name
new_file = self.tmp_file_1.name
new_name = utils.unique_file(new_file)
# Now let's create our expected result
result_split = os.path.splitext(tmp_file.name)
result_split = os.path.splitext(self.tmp_file_1.name)
correct_result = result_split[0] + " (1)" + result_split[1]
# Don't forget to close the tmpfile
tmp_file.close()
self.assertEqual(new_name, correct_result)

def test_recursive_list_with_file(self):
expected_result = []
expected_result.append(Path(self.tmp_file_1.name))

file_list = []
file_list.append(self.tmp_file_1.name)
result = utils.get_recursive_filelist(file_list)

self.assertEqual(result, expected_result)

def test_recursive_list_with_directory(self):
expected_result = []
expected_result.append(Path(self.tmp_file_2.name))
expected_result.append(Path(self.tmp_file_1.name))
expected_result = sorted(expected_result)

file_list = []
file_list.append(self.tmp_dir.name)
result = utils.get_recursive_filelist(file_list)

self.assertEqual(result, expected_result)


if __name__ == "__main__":
unittest.main()

0 comments on commit 5993bfd

Please sign in to comment.