Permalink
Browse files

add test for mp3split hook

  • Loading branch information...
1 parent e0e4b4a commit a5a53ca6163b29fd94d9266d9ed4f0fb1376552d Bernd Schlapsi committed Oct 30, 2011
Showing with 58 additions and 4 deletions.
  1. +3 −3 mp3split.py
  2. +51 −0 tests/mp3split_test.py
  3. +2 −1 tests/rename_downloads_test.py
  4. +2 −0 tests/runtests.py
View
@@ -19,12 +19,12 @@ def mp3split(from_file, to_file):
logger.debug("mp3split: destination is %s", destination)
command = 'mp3splt -ft 10.00 -o "@f_@n" "%s" -d "%s"' % (from_file, destination)
logger.debug("mp3split: Executing %s", command)
- p = subprocess.Popen(command, shell=True)
+ p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# retcode[1] values:
# <0: error
# 0: success, script handle the copy by hand(snif, progress bar is not used)
- retcode = os.waitpid(p.pid, 0)
- logger.debug("mp3split: Child with pid %s returned %s", retcode[0], retcode[1])
+ stdout, stderr = p.communicate()
+ logger.debug("mp3split: Prozess returned %s", p.returncode)
os.remove(to_file)
logger.info("mp3split: Original file %s removed", to_file)
except OSError, e:
View
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import glob
+import os
+import shutil
+import unittest
+
+from gpodder import api
+from config import data
+import mp3split
+
+def get_splitfiles(from_filename):
+ path, filename = os.path.split(from_filename)
+ filename2, ext = os.path.splitext(filename)
+ files2delete = os.path.join(path, "%s_*%s" % (filename2, ext))
+ return glob.glob(files2delete)
+
+
+class TestRenameDownloads(unittest.TestCase):
+ def setUp(self):
+ self.client = api.PodcastClient()
+
+ url = data.TEST_PODCASTS['TinFoilHat']['url']
+ episodeno = data.TEST_PODCASTS['TinFoilHat']['episode']
+ self.podcast = self.client.get_podcast(url)
+ self.podcast_title = self.podcast.title
+
+ self.episode = self.podcast.get_episodes()[episodeno]
+ self.filename = self.episode._episode.local_filename(create=False, check_only=True)
+ self.title = self.episode.title
+
+ def tearDown(self):
+ self.client._db.close()
+
+ for splitfile in get_splitfiles(self.filename):
+ os.remove(splitfile)
+
+ def test_mp3split(self):
+ self.assertEqual(os.path.split(self.filename)[1], 'TFH-001.mp3')
+
+ basename, ext = os.path.splitext(self.filename)
+ filename_new = "%s-test%s" % (basename, ext)
+ shutil.copyfile(self.filename, filename_new)
+ mp3split.mp3split(self.filename, filename_new)
+
+ generated_files = get_splitfiles(self.filename)
+ self.assertEqual(len(generated_files), 2)
+
+ self.assertEqual(os.path.split(generated_files[0])[1], 'TFH-001_1.mp3')
+ self.assertEqual(os.path.split(generated_files[1])[1], 'TFH-001_2.mp3')
+
@@ -13,10 +13,11 @@ def setUp(self):
self.client = api.PodcastClient()
url = data.TEST_PODCASTS['TinFoilHat']['url']
+ episodeno = data.TEST_PODCASTS['TinFoilHat']['episode']
self.podcast = self.client.get_podcast(url)
self.podcast_title = self.podcast.title
- self.episode = self.podcast.get_episodes()[-1]
+ self.episode = self.podcast.get_episodes()[episodeno]
self.filename = self.episode._episode.local_filename(create=False, check_only=True)
self.title = self.episode.title
View
@@ -97,6 +97,7 @@ def init_data():
#import all test files
import bittorrent_test
import cmml_creator_test
+ import mp3split_test
import rename_downloads_test
import rm_ogg_cover_test
import rockbox_mp4_convert_test
@@ -108,6 +109,7 @@ def init_data():
suite = loader.loadTestsFromModule(bittorrent_test)
suite.addTests(loader.loadTestsFromModule(cmml_creator_test))
+ suite.addTests(loader.loadTestsFromModule(mp3split_test))
suite.addTests(loader.loadTestsFromModule(rename_downloads_test))
suite.addTests(loader.loadTestsFromModule(rm_ogg_cover_test))
suite.addTests(loader.loadTestsFromModule(rockbox_mp4_convert_test))

0 comments on commit a5a53ca

Please sign in to comment.