From aa514032f5a8131607e5c0b1dc0f92852388b012 Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Sun, 21 Jul 2013 21:50:58 +1000 Subject: [PATCH] Also check for the output file without the _ in the filename to see if it exists --- libfilemanager.py | 5 +++++ tests/libfilemanagertest.py | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/libfilemanager.py b/libfilemanager.py index 413e2b5..735b9f2 100644 --- a/libfilemanager.py +++ b/libfilemanager.py @@ -38,6 +38,11 @@ class EncodeData: if os.path.exists(self.outputfile): errors.append("FILE_EXISTS") + if self.outputfile[-5:-4] == "_": + tempoutfile = self.outputfile[:-5] + self.outputfile[-4:] + if os.path.exists(tempoutfile): + errors.append("FILE_EXISTS") + return errors diff --git a/tests/libfilemanagertest.py b/tests/libfilemanagertest.py index c986f73..0e22626 100644 --- a/tests/libfilemanagertest.py +++ b/tests/libfilemanagertest.py @@ -8,6 +8,8 @@ Created on Fri Jul 5 14:12:26 2013 import unittest import os import sys +import minimock +from minimock import mock parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parentdir) from libfilemanager import EncodeData @@ -24,6 +26,27 @@ class libfilemanagertest(unittest.TestCase): "{2}\n".format(showname, inputname, outputname) self.assertEqual(result, expected) + def test_EncodeDataCheckProblemsFileExists(self): + showname = "test show" + inputname = "test input" + outputname = "test_output.mkv" + data = EncodeData(showname, inputname, outputname) + mock("os.path.exists", returns=True) + + result = data.checkproblems() + + self.assertIn("FILE_EXISTS", result) + + def test_EncodeDataCheckProblemsFile_Exists(self): + showname = "test show" + inputname = "test input" + outputname = "test_output_.mkv" + data = EncodeData(showname, inputname, outputname) + mock("os.path.exists", returns_iter=[False, True]) + result = data.checkproblems() + self.assertIn("FILE_EXISTS", result) + if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(libfilemanagertest) - unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file + unittest.TextTestRunner(verbosity=2).run(suite) + minimock.restore()