[Tutor] Newbie & Unittest ...
Damon Timm
damontimm at gmail.com
Thu May 6 02:37:20 CEST 2010
Hi - am trying to write some unit tests for my little python project -
I had been hard coding them when necessary here or there but I figured
it was time to try and learn how to do it properly.
I've read over Python's guide
(http://docs.python.org/library/unittest.html) but I am having a hard
time understanding how I can apply it *properly* to my first test case
...
What I am trying to do is straightforward, I am just not sure how to
populate the tests easily. Here is what I want to accomplish:
# code
import unittest
from mlc.filetypes import * # the module I am testing
# here are the *correct* key, value pairs I am testing against
TAG_VALUES = (
('title', 'Christmas Waltz'),
('artist', 'Damon Timm'),
('album', 'Homemade'),
)
# list of different file types that I want to test my tag grabbing capabilities
# the tags inside these files are set to match my TAG_VALUES
# I want to make sure my code is extracting them correctly
FILES = (
FLACFile('data/lossless/01 - Christmas Waltz.flac'),
MP3File('data/lossy/04 - Christmas Waltz (MP3-79).mp3'),
OGGFile('data/lossy/01 - Christmas Waltz (OGG-77).ogg'),
MP4File('data/lossy/06 - Christmas Waltz (M4A-64).m4a'),
)
class TestFiles(unittest.TestCase):
# this is the basic test
def test_values(self):
'''see if values from my object match what they should match'''
for file in FILES:
for k, v in TAG_VALUES:
self.assertEqual(self.file.tags[k], v)
This test works, however, it only runs as *one* test (which either
fails or passes) and I want it to run as 12 different tests (three for
each file type) and be able to see which key is failing for which file
type. I know I could write them all out individually but that seems
unnecessary.
I suspect my answer lies in the Suites but I can't wrap my head around it.
Thanks!
Damon
More information about the Tutor
mailing list