
import os
import sys
import unittest

sys.path.append(os.path.join(os.path.abspath(sys.path[0]), ".."))
from utils import FileParser, warn
from tvnamer_exceptions import InvalidFilename

from test_files import files

class test_filenames(unittest.TestCase):
    def setUp(self):
        pass
    
    def test_go(self):
        for category, testcases in files.items():
            for curtest in testcases:
                parser = FileParser(curtest['input'])
                theep = parser.parse()
                self.assertEquals(theep.seasonnumber, curtest['seasonnumber'])
                self.assertEquals(theep.episodenumber, curtest['episodenumber'])

if __name__ == '__main__':
    unittest.main()

import os
import sys
from copy import copy
import unittest

sys.path.append(os.path.join(os.path.abspath(sys.path[0]), ".."))
from utils import FileParser

from test_files import files

def check_test(curtest):
    """Runs test case, used by test_generator
    """
    parser = FileParser(curtest['input'])
    theep = parser.parse()
    assert theep.seriesname.lower() == curtest['seriesname'].lower()
    assert theep.seasonnumber == curtest['seasonnumber']
    assert theep.episodenumber == curtest['episodenumber']

def test_generator():
    """Generates test for each test case in test_files.py
    """
    for category, testcases in files.items():
        for testindex, curtest in enumerate(testcases):
            cur_tester = lambda x: check_test(x)
            cur_tester.description = '%s_%d' % (category, testindex)
            yield (cur_tester, curtest)

if __name__ == '__main__':
    import nose
    nose.main()

Use nose's test generator function
Use nose's test generator function
  
  import os
  import sys
+ from copy import copy
  import unittest
  
  sys.path.append(os.path.join(os.path.abspath(sys.path[0]), ".."))
- from utils import FileParser, warn
+ from utils import FileParser
- from tvnamer_exceptions import InvalidFilename
  
  from test_files import files
  
- class test_filenames(unittest.TestCase):
-     def setUp(self):
-         pass
-     
-     def test_go(self):
+ def check_test(curtest):
+     """Runs test case, used by test_generator
+     """
+     parser = FileParser(curtest['input'])
+     theep = parser.parse()
+     assert theep.seriesname.lower() == curtest['seriesname'].lower()
+     assert theep.seasonnumber == curtest['seasonnumber']
+     assert theep.episodenumber == curtest['episodenumber']
+ 
+ def test_generator():
+     """Generates test for each test case in test_files.py
+     """
-         for category, testcases in files.items():
+     for category, testcases in files.items():
+         for testindex, curtest in enumerate(testcases):
+             cur_tester = lambda x: check_test(x)
+             cur_tester.description = '%s_%d' % (category, testindex)
+             yield (cur_tester, curtest)
-             for curtest in testcases:
-                 parser = FileParser(curtest['input'])
-                 theep = parser.parse()
-                 self.assertEquals(theep.seasonnumber, curtest['seasonnumber'])
-                 self.assertEquals(theep.episodenumber, curtest['episodenumber'])
  
  if __name__ == '__main__':
+     import nose
-     unittest.main()
+     nose.main()
+ 
Use nose's test generator function
## Code Before:

import os
import sys
import unittest

sys.path.append(os.path.join(os.path.abspath(sys.path[0]), ".."))
from utils import FileParser, warn
from tvnamer_exceptions import InvalidFilename

from test_files import files

class test_filenames(unittest.TestCase):
    def setUp(self):
        pass
    
    def test_go(self):
        for category, testcases in files.items():
            for curtest in testcases:
                parser = FileParser(curtest['input'])
                theep = parser.parse()
                self.assertEquals(theep.seasonnumber, curtest['seasonnumber'])
                self.assertEquals(theep.episodenumber, curtest['episodenumber'])

if __name__ == '__main__':
    unittest.main()
## Instruction:
Use nose's test generator function
## Code After:

import os
import sys
from copy import copy
import unittest

sys.path.append(os.path.join(os.path.abspath(sys.path[0]), ".."))
from utils import FileParser

from test_files import files

def check_test(curtest):
    """Runs test case, used by test_generator
    """
    parser = FileParser(curtest['input'])
    theep = parser.parse()
    assert theep.seriesname.lower() == curtest['seriesname'].lower()
    assert theep.seasonnumber == curtest['seasonnumber']
    assert theep.episodenumber == curtest['episodenumber']

def test_generator():
    """Generates test for each test case in test_files.py
    """
    for category, testcases in files.items():
        for testindex, curtest in enumerate(testcases):
            cur_tester = lambda x: check_test(x)
            cur_tester.description = '%s_%d' % (category, testindex)
            yield (cur_tester, curtest)

if __name__ == '__main__':
    import nose
    nose.main()
