Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add test for mp3split hook

  • Loading branch information...
commit a5a53ca6163b29fd94d9266d9ed4f0fb1376552d 1 parent e0e4b4a
Bernd Schlapsi authored October 30, 2011
6  mp3split.py
@@ -19,12 +19,12 @@ def mp3split(from_file, to_file):
19 19
         logger.debug("mp3split: destination is %s", destination)
20 20
         command = 'mp3splt -ft 10.00 -o "@f_@n" "%s" -d "%s"' % (from_file, destination)
21 21
         logger.debug("mp3split: Executing %s", command)
22  
-        p = subprocess.Popen(command, shell=True)
  22
+        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
23 23
         # retcode[1] values:
24 24
         #  <0: error
25 25
         #   0: success, script handle the copy by hand(snif, progress bar is not used)
26  
-        retcode = os.waitpid(p.pid, 0)
27  
-        logger.debug("mp3split: Child with pid %s returned %s", retcode[0], retcode[1])
  26
+        stdout, stderr = p.communicate()
  27
+        logger.debug("mp3split: Prozess returned %s", p.returncode)
28 28
         os.remove(to_file)
29 29
         logger.info("mp3split: Original file %s removed", to_file)
30 30
     except OSError, e:
51  tests/mp3split_test.py
... ...
@@ -0,0 +1,51 @@
  1
+#!/usr/bin/python
  2
+# -*- coding: utf-8 -*-
  3
+import glob
  4
+import os
  5
+import shutil
  6
+import unittest
  7
+
  8
+from gpodder import api
  9
+from config import data
  10
+import mp3split
  11
+
  12
+def get_splitfiles(from_filename):
  13
+    path, filename = os.path.split(from_filename)
  14
+    filename2, ext = os.path.splitext(filename)
  15
+    files2delete = os.path.join(path, "%s_*%s" % (filename2, ext))
  16
+    return glob.glob(files2delete)
  17
+
  18
+
  19
+class TestRenameDownloads(unittest.TestCase):
  20
+    def setUp(self):
  21
+        self.client = api.PodcastClient()
  22
+
  23
+        url = data.TEST_PODCASTS['TinFoilHat']['url']
  24
+        episodeno = data.TEST_PODCASTS['TinFoilHat']['episode']
  25
+        self.podcast = self.client.get_podcast(url)
  26
+        self.podcast_title = self.podcast.title
  27
+
  28
+        self.episode = self.podcast.get_episodes()[episodeno]
  29
+        self.filename = self.episode._episode.local_filename(create=False, check_only=True)
  30
+        self.title = self.episode.title
  31
+
  32
+    def tearDown(self):
  33
+        self.client._db.close()
  34
+
  35
+        for splitfile in get_splitfiles(self.filename):
  36
+            os.remove(splitfile)
  37
+
  38
+    def test_mp3split(self):
  39
+        self.assertEqual(os.path.split(self.filename)[1], 'TFH-001.mp3')
  40
+
  41
+        basename, ext = os.path.splitext(self.filename)
  42
+        filename_new = "%s-test%s" % (basename, ext)
  43
+        shutil.copyfile(self.filename, filename_new)
  44
+        mp3split.mp3split(self.filename, filename_new)
  45
+
  46
+        generated_files = get_splitfiles(self.filename)
  47
+        self.assertEqual(len(generated_files), 2)
  48
+
  49
+        self.assertEqual(os.path.split(generated_files[0])[1], 'TFH-001_1.mp3')
  50
+        self.assertEqual(os.path.split(generated_files[1])[1], 'TFH-001_2.mp3')
  51
+
3  tests/rename_downloads_test.py
@@ -13,10 +13,11 @@ def setUp(self):
13 13
         self.client = api.PodcastClient()
14 14
 
15 15
         url = data.TEST_PODCASTS['TinFoilHat']['url']
  16
+        episodeno = data.TEST_PODCASTS['TinFoilHat']['episode']
16 17
         self.podcast = self.client.get_podcast(url)
17 18
         self.podcast_title = self.podcast.title
18 19
 
19  
-        self.episode = self.podcast.get_episodes()[-1]
  20
+        self.episode = self.podcast.get_episodes()[episodeno]
20 21
         self.filename = self.episode._episode.local_filename(create=False, check_only=True)
21 22
         self.title = self.episode.title
22 23
 
2  tests/runtests.py
@@ -97,6 +97,7 @@ def init_data():
97 97
     #import all test files
98 98
     import bittorrent_test
99 99
     import cmml_creator_test
  100
+    import mp3split_test
100 101
     import rename_downloads_test
101 102
     import rm_ogg_cover_test
102 103
     import rockbox_mp4_convert_test
@@ -108,6 +109,7 @@ def init_data():
108 109
 
109 110
     suite = loader.loadTestsFromModule(bittorrent_test)
110 111
     suite.addTests(loader.loadTestsFromModule(cmml_creator_test))
  112
+    suite.addTests(loader.loadTestsFromModule(mp3split_test))
111 113
     suite.addTests(loader.loadTestsFromModule(rename_downloads_test))
112 114
     suite.addTests(loader.loadTestsFromModule(rm_ogg_cover_test))
113 115
     suite.addTests(loader.loadTestsFromModule(rockbox_mp4_convert_test))

0 notes on commit a5a53ca

Please sign in to comment.
Something went wrong with that request. Please try again.