示例#1
0
    def test_cmdenv(self):
        import logging
        logging.basicConfig()
        # make sure previous environment is preserved
        os.environ['SOMETHING'] = 'foofoofoo'
        old_env = os.environ.copy()

        mr_job = MRTestCmdenv(['--runner', 'inline', '--cmdenv=FOO=bar'])
        mr_job.sandbox(stdin=BytesIO(b'foo\n'))

        results = []

        with mr_job.make_runner() as runner:
            assert isinstance(runner, InlineMRJobRunner)
            runner.run()

            for line in runner.stream_output():
                key, value = mr_job.parse_output_line(line)
                results.append((key, value))

        self.assertEqual(sorted(results),
                         [('FOO', 'bar'), ('SOMETHING', 'foofoofoo')])

        # make sure we revert back
        self.assertEqual(old_env, os.environ)
示例#2
0
    def test_cmdenv(self):
        input_path = os.path.join(self.tmp_dir, 'input')
        with open(input_path, 'w') as input_file:
            input_file.write('foo\n')

        # make sure previous environment is preserved
        os.environ['SOMETHING'] = 'foofoofoo'
        old_env = os.environ.copy()

        mr_job = MRTestCmdenv(['--runner', 'inline',
                               '-c', self.mrjob_conf_path,
                               '--cmdenv=FOO=bar', input_path])
        mr_job.sandbox()

        results = []

        with mr_job.make_runner() as runner:
            assert isinstance(runner, InlineMRJobRunner)
            runner.run()

            for line in runner.stream_output():
                key, value = mr_job.parse_output_line(line)
                results.append((key, value))

        self.assertEqual(sorted(results),
                         [('FOO', 'bar'), ('SOMETHING', 'foofoofoo')])

        # make sure we revert back
        self.assertEqual(old_env, os.environ)
示例#3
0
    def test_cmdenv(self):
        import logging

        logging.basicConfig()
        # make sure previous environment is preserved
        os.environ["SOMETHING"] = "foofoofoo"
        old_env = os.environ.copy()

        mr_job = MRTestCmdenv(["--runner", "inline", "--cmdenv=FOO=bar"])
        mr_job.sandbox(stdin=StringIO("foo\n"))

        results = []

        with mr_job.make_runner() as runner:
            assert isinstance(runner, InlineMRJobRunner)
            runner.run()

            for line in runner.stream_output():
                key, value = mr_job.parse_output_line(line)
                results.append((key, value))

        self.assertEqual(sorted(results), [("FOO", "bar"), ("SOMETHING", "foofoofoo")])

        # make sure we revert back
        self.assertEqual(old_env, os.environ)
示例#4
0
    def test_cmdenv(self):
        input_path = os.path.join(self.tmp_dir, 'input')
        with open(input_path, 'w') as input_file:
            input_file.write('foo\n')

        # make sure previous environment is preserved
        os.environ['SOMETHING'] = 'foofoofoo'
        old_env = os.environ.copy()

        mr_job = MRTestCmdenv([
            '--runner', 'inline', '-c', self.mrjob_conf_path,
            '--cmdenv=FOO=bar', input_path
        ])
        mr_job.sandbox()

        results = []

        with mr_job.make_runner() as runner:
            assert isinstance(runner, InlineMRJobRunner)
            runner.run()

            for line in runner.stream_output():
                key, value = mr_job.parse_output_line(line)
                results.append((key, value))

        self.assertEqual(sorted(results), [('FOO', 'bar'),
                                           ('SOMETHING', 'foofoofoo')])

        # make sure we revert back
        self.assertEqual(old_env, os.environ)
示例#5
0
    def test_cmdenv(self):
        input_path = os.path.join(self.tmp_dir, "input")
        with open(input_path, "w") as input_file:
            input_file.write("foo\n")

        # make sure previous environment is preserved
        os.environ["SOMETHING"] = "foofoofoo"
        old_env = os.environ.copy()

        mr_job = MRTestCmdenv(["--runner", "inline", "-c", self.mrjob_conf_path, "--cmdenv=FOO=bar", input_path])
        mr_job.sandbox()

        results = []

        with mr_job.make_runner() as runner:
            assert isinstance(runner, InlineMRJobRunner)
            runner.run()

            for line in runner.stream_output():
                key, value = mr_job.parse_output_line(line)
                results.append((key, value))

        self.assertEqual(sorted(results), [("FOO", "bar"), ("SOMETHING", "foofoofoo")])

        # make sure we revert back
        self.assertEqual(old_env, os.environ)