def test_loading_boostrapped_mrjob_library(self): # track the dir we're loading mrjob from rather than the full path # to deal with edge cases where we load from the .py file, # and the script loads from the .pyc compiled from that .py file. our_mrjob_dir = os.path.dirname(os.path.realpath(mrjob.__file__)) with mrjob_conf_patcher(): mr_job = MRJobWhereAreYou(['-r', 'local']) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner.get_opts()['bootstrap_mrjob'], True) local_tmp_dir = os.path.realpath(runner._get_local_tmp_dir()) runner.run() output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should load mrjob from its working dir _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertNotEqual(our_mrjob_dir, script_mrjob_dir) assert script_mrjob_dir.startswith(local_tmp_dir)
def test_can_turn_off_bootstrap_mrjob(self): with mrjob_conf_patcher({"runners": {"local": {"bootstrap_mrjob": False}}}): mr_job = MRJobWhereAreYou(["-r", "local"]) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner.get_opts()["bootstrap_mrjob"], False) local_tmp_dir = os.path.realpath(runner._get_local_tmp_dir()) try: with no_handlers_for_logger(): runner.run() except Exception as e: # if mrjob is not installed, script won't be able to run self.assertIn("ImportError", str(e)) return output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should not load mrjob from local_tmp_dir _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertFalse(script_mrjob_dir.startswith(local_tmp_dir))
def test_can_turn_off_bootstrap_mrjob(self): # track the dir we're loading mrjob from rather than the full path # to deal with edge cases where we load from the .py file, # and the script loads from the .pyc compiled from that .py file. our_mrjob_dir = os.path.dirname(os.path.realpath(mrjob.__file__)) self.mrjob_conf_path = os.path.join(self.tmp_dir, 'mrjob.conf') dump_mrjob_conf({'runners': {'local': {'bootstrap_mrjob': False}}}, open(self.mrjob_conf_path, 'w')) mr_job = MRJobWhereAreYou(['-c', self.mrjob_conf_path]) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner.get_opts()['bootstrap_mrjob'], False) runner.run() output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should load mrjob from the same place our test does _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertEqual(our_mrjob_dir, script_mrjob_dir)
def test_can_turn_off_bootstrap_mrjob(self): with mrjob_conf_patcher( {'runners': {'local': {'bootstrap_mrjob': False}}}): mr_job = MRJobWhereAreYou(['-r', 'local']) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner._opts['bootstrap_mrjob'], False) local_tmp_dir = os.path.realpath(runner._get_local_tmp_dir()) try: runner.run() except StepFailedException: # this is what happens when mrjob isn't installed elsewhere return # however, if mrjob is installed, we need to verify that # we're using the installed version and not a bootstrapped copy output = list(mr_job.parse_output(runner.cat_output())) self.assertEqual(len(output), 1) # script should not load mrjob from local_tmp_dir _, script_mrjob_dir = output[0] self.assertFalse(script_mrjob_dir.startswith(local_tmp_dir))
def test_can_turn_off_bootstrap_mrjob(self): with mrjob_conf_patcher( {'runners': { 'local': { 'bootstrap_mrjob': False } }}): mr_job = MRJobWhereAreYou(['-r', 'local']) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner.get_opts()['bootstrap_mrjob'], False) local_tmp_dir = os.path.realpath(runner._get_local_tmp_dir()) try: with no_handlers_for_logger(): runner.run() except Exception as e: # if mrjob is not installed, script won't be able to run self.assertIn('ImportError', str(e)) return output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should not load mrjob from local_tmp_dir _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertFalse(script_mrjob_dir.startswith(local_tmp_dir))
def test_loading_boostrapped_mrjob_library(self): # track the dir we're loading mrjob from rather than the full path # to deal with edge cases where we load from the .py file, # and the script loads from the .pyc compiled from that .py file. our_mrjob_dir = os.path.dirname(os.path.realpath(mrjob.__file__)) with mrjob_conf_patcher(): mr_job = MRJobWhereAreYou(['-r', 'local', '--bootstrap-mrjob']) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner._bootstrap_mrjob(), True) local_tmp_dir = os.path.realpath(runner._get_local_tmp_dir()) runner.run() output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should load mrjob from its working dir _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertNotEqual(our_mrjob_dir, script_mrjob_dir) self.assertTrue(script_mrjob_dir.startswith(local_tmp_dir))
def test_can_turn_off_bootstrap_mrjob(self): with mrjob_conf_patcher( {'runners': { 'local': { 'bootstrap_mrjob': False } }}): mr_job = MRJobWhereAreYou(['-r', 'local']) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner.get_opts()['bootstrap_mrjob'], False) local_tmp_dir = os.path.realpath(runner._get_local_tmp_dir()) try: with no_handlers_for_logger(): runner.run() except StepFailedException: # this is what happens when mrjob isn't installed elsewhere return # however, if mrjob is installed, we need to verify that # we're using the installed version and not a bootstrapped copy output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should not load mrjob from local_tmp_dir _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertFalse(script_mrjob_dir.startswith(local_tmp_dir))
def test_can_turn_off_bootstrap_mrjob(self): # track the dir we're loading mrjob from rather than the full path # to deal with edge cases where we load from the .py file, # and the script loads from the .pyc compiled from that .py file. our_mrjob_dir = os.path.dirname(os.path.realpath(mrjob.__file__)) self.mrjob_conf_path = os.path.join(self.tmp_dir, 'mrjob.conf') dump_mrjob_conf({'runners': { 'local': { 'bootstrap_mrjob': False } }}, open(self.mrjob_conf_path, 'w')) mr_job = MRJobWhereAreYou(['-c', self.mrjob_conf_path, '-r', 'local']) mr_job.sandbox() with mr_job.make_runner() as runner: # sanity check self.assertEqual(runner.get_opts()['bootstrap_mrjob'], False) runner.run() output = list(runner.stream_output()) self.assertEqual(len(output), 1) # script should load mrjob from the same place our test does _, script_mrjob_dir = mr_job.parse_output_line(output[0]) self.assertEqual(our_mrjob_dir, script_mrjob_dir)