Skip to content

Commit

Permalink
replaced unclear list/map construct with a simpler for loop
Browse files Browse the repository at this point in the history
Performed some supporting unit test improvements.
  • Loading branch information
AaronRobson committed Feb 21, 2021
1 parent 5336b8e commit e1e8e04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion UnrealSoundsExtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def DoExtraction(input, output, flatten):
filename,
os.path.join(os.path.abspath(output), ''))
for filename in filenames]
list(map(os.system, commands))
for command in commands:
os.system(command)
else:
raise OSError(
'No Files to Extract from in: {0}.'.format(repr(soundsDirectory)))
Expand Down
25 changes: 25 additions & 0 deletions tests/test_UnrealSoundsExtract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python

import unittest
from unittest.mock import patch
import os.path

import UnrealSoundsExtract as ute
Expand All @@ -25,3 +26,27 @@ def test_no_sub_folder(self):
actual = self.givenExtractorFilepath + \
' batchexport {0} sound wav "{1}"'
self.assertEqual(given, actual)

@patch('os.system', return_value=None)
@patch('UnrealSoundsExtract.GetFilenamesInDirectory', return_value=[])
class TestDoExtraction(unittest.TestCase):
def setUp(self):
self.given_input = os.path.join('.')
self.given_output = os.path.join('.', 'SoundsInWav')
self.given_flatten = False
self.expected_sounds_directory = os.path.join(self.given_input, 'Sounds')

def test_no_files(self, mock_get_filenames_in_directory, mock_os_system):
with self.assertRaisesRegex(OSError, r'^No Files to Extract from in:'):
ute.DoExtraction(self.given_input, self.given_output, self.given_flatten)
mock_get_filenames_in_directory.assert_called_with(self.expected_sounds_directory)
mock_os_system.assert_not_called()

def test_multiple_files(self, mock_get_filenames_in_directory, mock_os_system):
mock_get_filenames_in_directory.return_value = [
os.path.join(self.expected_sounds_directory, 'abc.uax'),
os.path.join(self.expected_sounds_directory, 'xyz.uax'),
]
self.assertIsNone(ute.DoExtraction(self.given_input, self.given_output, self.given_flatten))
mock_get_filenames_in_directory.assert_called_with(self.expected_sounds_directory)
self.assertEqual(mock_os_system.call_count, 2)

0 comments on commit e1e8e04

Please sign in to comment.