# Path: pydoop/test_utils.py
# class WDTestCase(unittest.TestCase):
# 
#     def setUp(self):
#         self.wd = tempfile.mkdtemp(prefix='pydoop_test_')
# 
#     def tearDown(self):
#         shutil.rmtree(self.wd)
# 
#     def _mkfn(self, basename):
#         return os.path.join(self.wd, basename)
# 
#     def _mkf(self, basename, mode='w'):
#         return open(self._mkfn(basename), mode)


import io
import os
import unittest
import pydoop.mapreduce.api as api
import pydoop.mapreduce.binary_protocol as bp
import pydoop.mapreduce.pipes as pipes
import pydoop.sercore as sercore
from pydoop.test_utils import WDTestCase
        factory = pipes.Factory(Mapper)
        self.__run_test(M_NAME, factory, private_encoding=False)

    def test_reduce(self):
        factory = pipes.Factory(Mapper, reducer_class=Reducer)
        self.__run_test(R_NAME, factory)

    def __run_test(self, name, factory, **kwargs):
        orig_path = os.path.join(THIS_DIR, name)
        cmd_path = os.path.join(self.wd, name)
        with io.open(orig_path, "rb") as fi, io.open(cmd_path, "wb") as fo:
            fo.write(fi.read())
        os.environ["mapreduce.pipes.commandfile"] = cmd_path
        pipes.run_task(factory, **kwargs)
        out_cmd_path = "%s.out" % cmd_path
        self.assertTrue(os.path.exists(out_cmd_path))
        with sercore.FileInStream(out_cmd_path) as stream:
            out_cmds = set(cmd for cmd, _ in UplinkDumpReader(stream))
        self.assertEqual(out_cmds, {bp.OUTPUT, bp.PROGRESS})


def suite():
    suite_ = unittest.TestSuite()
    suite_.addTest(TestFileConnection('test_map'))
    suite_.addTest(TestFileConnection('test_reduce'))
    return suite_


if __name__ == '__main__':
    _RUNNER = unittest.TextTestRunner(verbosity=2)

# Path: pydoop/test_utils.py
# class WDTestCase(unittest.TestCase):
# 
#     def setUp(self):
#         self.wd = tempfile.mkdtemp(prefix='pydoop_test_')
# 
#     def tearDown(self):
#         shutil.rmtree(self.wd)
# 
#     def _mkfn(self, basename):
#         return os.path.join(self.wd, basename)
# 
#     def _mkf(self, basename, mode='w'):
#         return open(self._mkfn(basename), mode)


# Path: test/mapreduce/test_connections.py
import io
import os
import unittest
import pydoop.mapreduce.api as api
import pydoop.mapreduce.binary_protocol as bp
import pydoop.mapreduce.pipes as pipes
import pydoop.sercore as sercore
from pydoop.test_utils import WDTestCase

        factory = pipes.Factory(Mapper)
        self.__run_test(M_NAME, factory, private_encoding=False)

    def test_reduce(self):
        factory = pipes.Factory(Mapper, reducer_class=Reducer)
        self.__run_test(R_NAME, factory)

    def __run_test(self, name, factory, **kwargs):
        orig_path = os.path.join(THIS_DIR, name)
        cmd_path = os.path.join(self.wd, name)
        with io.open(orig_path, "rb") as fi, io.open(cmd_path, "wb") as fo:
            fo.write(fi.read())
        os.environ["mapreduce.pipes.commandfile"] = cmd_path
        pipes.run_task(factory, **kwargs)
        out_cmd_path = "%s.out" % cmd_path
        self.assertTrue(os.path.exists(out_cmd_path))
        with sercore.FileInStream(out_cmd_path) as stream:
            out_cmds = set(cmd for cmd, _ in UplinkDumpReader(stream))
        self.assertEqual(out_cmds, {bp.OUTPUT, bp.PROGRESS})


def suite():
    suite_ = unittest.TestSuite()
    suite_.addTest(TestFileConnection('test_map'))
    suite_.addTest(TestFileConnection('test_reduce'))
    return suite_


if __name__ == '__main__':
    _RUNNER = unittest.TextTestRunner(verbosity=2)

    _RUNNER.run((suite()))