예제 #1
0
파일: test_local.py 프로젝트: alanhdu/mrjob
 def test_multiple_2(self):
     data = b"x\ny\nz\n"
     job = CmdJob(["--mapper-cmd=cat", "--reducer-cmd-2", "wc -l", "--runner=local", "--no-conf"])
     job.sandbox(stdin=BytesIO(data))
     with job.make_runner() as r:
         r.run()
         self.assertEqual(sum(int(l) for l in r.stream_output()), 3)
예제 #2
0
 def test_multiple_2(self):
     data = 'x\ny\nz\n'
     job = CmdJob(['--mapper-cmd=cat', '--reducer-cmd-2', 'wc -l',
                   '--runner=local', '--no-conf'])
     job.sandbox(stdin=StringIO(data))
     with job.make_runner() as r:
         r.run()
         self.assertEqual(sum(int(l) for l in r.stream_output()), 3)
예제 #3
0
파일: test_local.py 프로젝트: alanhdu/mrjob
    def test_cat_mapper(self):
        data = b"x\ny\nz\n"
        job = CmdJob(["--mapper-cmd=cat", "--runner=local"])
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(r._get_steps(), [{"type": "streaming", "mapper": {"type": "command", "command": "cat"}}])

            r.run()
            lines = [line.strip() for line in list(r.stream_output())]
            self.assertEqual(sorted(lines), sorted(data.split()))
예제 #4
0
파일: test_local.py 프로젝트: SeanOC/mrjob
    def test_cat_mapper(self):
        data = 'x\ny\nz\n'
        job = CmdJob(['--mapper-cmd=cat', '--runner=local'])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {
                        'type': 'command',
                        'command': 'cat'}}])

            r.run()
            lines = [line.strip() for line in list(r.stream_output())]
            self.assertItemsEqual(lines, data.split())
예제 #5
0
    def test_cat_mapper(self):
        data = 'x\ny\nz\n'
        job = CmdJob(['--mapper-cmd=cat', '--runner=local'])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {
                        'type': 'command',
                        'command': 'cat'}}])

            r.run()

            self.assertEqual(''.join(r.stream_output()), data)
예제 #6
0
    def test_cat_mapper(self):
        data = 'x\ny\nz\n'
        job = CmdJob(['--mapper-cmd=cat', '--runner=local'])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {
                        'type': 'command',
                        'command': 'cat'}}])

            r.run()

            self.assertEqual(''.join(r.stream_output()), data)
예제 #7
0
    def test_cat_mapper(self):
        data = b'x\ny\nz\n'
        job = CmdJob(['--mapper-cmd=cat', '--runner=local'])
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(r._get_steps(), [{
                'type': 'streaming',
                'mapper': {
                    'type': 'command',
                    'command': 'cat'
                }
            }])

            r.run()
            lines = [line.strip() for line in list(r.stream_output())]
            self.assertEqual(sorted(lines), sorted(data.split()))
예제 #8
0
    def test_cat_reducer(self):
        data = b'x\ny\nz\n'
        job = CmdJob(['--reducer-cmd', 'cat -e', '--runner=local'])
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(r._get_steps(), [{
                'type': 'streaming',
                'mapper': {
                    'type': 'script',
                },
                'reducer': {
                    'type': 'command',
                    'command': 'cat -e'
                }
            }])

            r.run()

            lines = list(r.stream_output())
            self.assertEqual(sorted(lines), [b'x$\n', b'y$\n', b'z$\n'])
예제 #9
0
    def test_cat_reducer(self):
        data = 'x\ny\nz\n'
        job = CmdJob(['--reducer-cmd', 'cat -e', '--runner=local'])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {
                        'type': 'script',
                    },
                    'reducer': {
                        'type': 'command',
                        'command': 'cat -e'}}])

            r.run()

            lines = list(r.stream_output())
            self.assertEqual(lines, ['x$\n', 'y$\n', 'z$\n'])
예제 #10
0
파일: test_local.py 프로젝트: alanhdu/mrjob
    def test_cat_reducer(self):
        data = b"x\ny\nz\n"
        job = CmdJob(["--reducer-cmd", "cat -e", "--runner=local"])
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [
                    {
                        "type": "streaming",
                        "mapper": {"type": "script"},
                        "reducer": {"type": "command", "command": "cat -e"},
                    }
                ],
            )

            r.run()

            lines = list(r.stream_output())
            self.assertEqual(sorted(lines), [b"x$\n", b"y$\n", b"z$\n"])
예제 #11
0
    def test_uniq_combiner(self):
        data = b'x\nx\nx\nx\nx\nx\n'
        job = CmdJob(['--combiner-cmd=uniq', '--runner=local'])
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(r._get_steps(), [{
                'type': 'streaming',
                'mapper': {
                    'type': 'script',
                },
                'combiner': {
                    'type': 'command',
                    'command': 'uniq'
                }
            }])

            r.run()

            # there are 2 map tasks, each of which has 1 combiner, and all rows
            # are the same, so we should end up with just 2 values

            self.assertEqual(b''.join(r.stream_output()), b'x\nx\n')
예제 #12
0
    def test_uniq_combiner(self):
        data = 'x\nx\nx\nx\nx\nx\n'
        job = CmdJob(['--combiner-cmd=uniq', '--runner=local'])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {
                        'type': 'script',
                    },
                    'combiner': {
                        'type': 'command',
                        'command': 'uniq'}}])

            r.run()

            # there are 2 map tasks, each of which has 1 combiner, and all rows
            # are the same, so we should end up with just 2 values

            self.assertEqual(''.join(r.stream_output()), 'x\nx\n')
예제 #13
0
파일: test_local.py 프로젝트: alanhdu/mrjob
    def test_uniq_combiner(self):
        data = b"x\nx\nx\nx\nx\nx\n"
        job = CmdJob(["--combiner-cmd=uniq", "--runner=local"])
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [
                    {
                        "type": "streaming",
                        "mapper": {"type": "script"},
                        "combiner": {"type": "command", "command": "uniq"},
                    }
                ],
            )

            r.run()

            # there are 2 map tasks, each of which has 1 combiner, and all rows
            # are the same, so we should end up with just 2 values

            self.assertEqual(b"".join(r.stream_output()), b"x\nx\n")
예제 #14
0
    def test_multiple(self):
        data = 'x\nx\nx\nx\nx\nx\n'
        mapper_cmd = 'cat -e'
        reducer_cmd = bash_wrap('wc -l | tr -Cd "[:digit:]"')
        job = CmdJob([
            '--runner', 'local',
            '--mapper-cmd', mapper_cmd,
            '--combiner-cmd', 'uniq',
            '--reducer-cmd', reducer_cmd])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {'type': 'command', 'command': mapper_cmd},
                    'combiner': {'type': 'command', 'command': 'uniq'},
                    'reducer': {'type': 'command', 'command': reducer_cmd},
                }])

            r.run()

            self.assertEqual(list(r.stream_output()), ['2'])
예제 #15
0
    def test_multiple(self):
        data = 'x\nx\nx\nx\nx\nx\n'
        mapper_cmd = 'cat -e'
        reducer_cmd = bash_wrap('wc -l | tr -Cd "[:digit:]"')
        job = CmdJob([
            '--runner', 'local',
            '--mapper-cmd', mapper_cmd,
            '--combiner-cmd', 'uniq',
            '--reducer-cmd', reducer_cmd])
        job.sandbox(stdin=StringIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [{
                    'type': 'streaming',
                    'mapper': {'type': 'command', 'command': mapper_cmd},
                    'combiner': {'type': 'command', 'command': 'uniq'},
                    'reducer': {'type': 'command', 'command': reducer_cmd},
                }])

            r.run()

            self.assertEqual(list(r.stream_output()), ['2'])
예제 #16
0
파일: test_local.py 프로젝트: alanhdu/mrjob
    def test_multiple(self):
        data = b"x\nx\nx\nx\nx\nx\n"
        mapper_cmd = "cat -e"
        reducer_cmd = bash_wrap('wc -l | tr -Cd "[:digit:]"')
        job = CmdJob(
            ["--runner", "local", "--mapper-cmd", mapper_cmd, "--combiner-cmd", "uniq", "--reducer-cmd", reducer_cmd]
        )
        job.sandbox(stdin=BytesIO(data))
        with job.make_runner() as r:
            self.assertEqual(
                r._get_steps(),
                [
                    {
                        "type": "streaming",
                        "mapper": {"type": "command", "command": mapper_cmd},
                        "combiner": {"type": "command", "command": "uniq"},
                        "reducer": {"type": "command", "command": reducer_cmd},
                    }
                ],
            )

            r.run()

            self.assertEqual(list(r.stream_output()), [b"2"])
예제 #17
0
    def test_passthrough_options(self):
        cmd_job = CmdJob(['--help'])

        output = self.stdout.getvalue()
        self.assertIn('--reducer-cmd-2', output)
예제 #18
0
    def test_passthrough_options(self):
        CmdJob(['--help'])
        self.exit.assert_called_once_with(0)

        output = self.stdout.getvalue()
        self.assertIn('--reducer-cmd-2', output)