mrjob workshop


Job Testing

In the same folder as before, create a file called test_wordcount.py:

import unittest

from wordcount import WordCount


class TestWordCount(unittest.TestCase):

    def setUp(self):
        self.job = WordCount()

    def test_word_count_mapper(self):
        line = 'oh hi pyowa!'

        self.assertEqual(self.job.mapper(None, line).next(), ('words', 3))


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

You will also need the wordcount.py file from the last exercise for this to work properly.

Now run the test:

$ python test_wordcount.py -vv
test_word_count_mapper (__main__.TestWordCount) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

Exercises