def test_death(self):
        """Test OutputPyJson handles exceptions on bad death()."""
        output = OutputPyJSON(gzip.GzipFile(self.tmp_file, 'w'))

        self.assertTrue(output.birth("{}"))
        self.assertTrue(output.death())
        self.assertTrue(output.death()) #close() on closed is a no-op
Exemple #2
0
    def test_command_line_args(self):
        """
        Check that Go handles command line args switch correctly.
        @param self. Object reference.
        """
        inputer = InputPyEmptyDocument(1)
        transformer = MapPyDoNothing()
        merger = ReducePyDoNothing()
        outputer = OutputPyJSON(open(self.tmp_file, 'w'))
        arg_temp = copy.deepcopy(sys.argv)
        sys.argv = [arg_temp[0]]

        Go(inputer, transformer, merger, outputer, config_file=self.config, \
                                                      command_line_args = True)

        outputer = OutputPyJSON(open(self.tmp_file, 'w'))
        arg_temp = copy.deepcopy(sys.argv)
        sys.argv = [arg_temp[0], "bob"]
        with self.assertRaises(SystemExit):
            Go(inputer, transformer, merger, outputer, \
                              config_file=self.config, command_line_args = True)

        sys.argv = [arg_temp[0], "-verbose_level", "1"]
        Go(inputer, transformer, merger, outputer, \
                             config_file=self.config, command_line_args = True)

        sys.argv = arg_temp
Exemple #3
0
    def test_death(self):
        """Test OutputPyJson handles exceptions on bad death()."""
        output = OutputPyJSON(gzip.GzipFile(self.tmp_file, 'w'))

        self.assertTrue(output.birth("{}"))
        self.assertTrue(output.death())
        self.assertTrue(output.death())  #close() on closed is a no-op
    def test_birth_text_format(self):
        """Test OutputPyJson loads a text file from datacards correctly."""
        output = OutputPyJSON()
        json_doc = json.dumps({"output_json_file_name":self.tmp_file,
                               "output_json_file_type":"text"})
        output.birth(json_doc)
        self.assertTrue(output.save(self.test_string))
        self.assertTrue(output.death())

        my_file = open(self.tmp_file, 'r')
        read_doc = json.loads(my_file.readline())
        self.assertEqual(read_doc, json.loads(self.test_string))
        my_file.close()
    def test_save_single_uncompressed(self):
        """Try saving one spill in uncompressed fashion
        """
        output = OutputPyJSON(open(self.tmp_file,'w'))

        self.assertTrue(output.birth("{}"))
        self.assertTrue(output.save(self.test_string))
        self.assertTrue(output.death())
        self.assertFalse(output.save(self.test_string)) # attempting to write to
                                                        # closed file
        test_doc = json.loads(self.test_string)

        my_file = open(self.tmp_file, 'r')
        read_doc = json.loads(my_file.readline())
        self.assertEqual(read_doc, test_doc)
        my_file.close()
Exemple #6
0
    def test_input_birth(self):
        """
        Check that Go raises error with bad input.
        @param self. Object reference.
        """
        inputer = FakeWorker()
        transformer = MapPyDoNothing()
        merger = ReducePyDoNothing()
        outputer = OutputPyJSON(open(self.tmp_file, 'w'))

        with self.assertRaises(AssertionError):
            Go(inputer, transformer, merger, outputer, \
                              config_file=self.config, command_line_args=False)
Exemple #7
0
 def test_dataflow_multi_process(self):
     """
     Check that Go executes okay with multi_process dataflow.
     @param self. Object reference.
     """
     inputer = InputPyEmptyDocument(1)
     transformer = MapPyDoNothing()
     merger = ReducePyDoNothing()
     outputer = OutputPyJSON(open(self.tmp_file, 'w'))
     for map_red_type in ['multi_process']:
         config = StringIO(u"""type_of_dataflow="%s" """ % map_red_type)
         with self.assertRaises(Exception):
             Go(inputer, transformer, merger, outputer, config, \
                    command_line_args = False)
Exemple #8
0
    def test_dataflow_single_thread(self):
        """
        Check that Go executes okay with pipeline_single_thread dataflow.
        @param self. Object reference.
        """
        inputer = InputPyEmptyDocument(1)
        transformer = MapPyDoNothing()
        merger = ReducePyDoNothing()
        outputer = OutputPyJSON(open(self.tmp_file, 'w'))
        for map_red_type in ['pipeline_single_thread']:
            config = StringIO(u"""type_of_dataflow="%s" """ % map_red_type)

            Go(inputer, transformer, merger, outputer, config, \
                   command_line_args = False)
Exemple #9
0
    def test_dataflow_not_implemented(self):
        """
        Check that Go notifies user of unimplemented dataflow.
        @param self. Object reference.
        """
        inputer = InputPyEmptyDocument(1)
        transformer = MapPyDoNothing()
        merger = ReducePyDoNothing()
        outputer = OutputPyJSON(open(self.tmp_file, 'w'))
        for map_red_type in ['many_local_threads']:
            config = StringIO(u"""type_of_dataflow="%s" """ % map_red_type)

            with self.assertRaises(NotImplementedError):
                Go(inputer, transformer, merger, outputer, config, \
                       command_line_args = False)
Exemple #10
0
    def test_type_of_dataflow_bad(self):
        """
        Check that Go raises error with bad dataflow type.
        @param self. Object reference.
        """
        inputer = InputPyEmptyDocument(1)
        transformer = MapPyDoNothing()
        merger = ReducePyDoNothing()
        outputer = OutputPyJSON(open(self.tmp_file, 'w'))

        config = StringIO(u"""type_of_dataflow="bad_type" """)

        with self.assertRaises(LookupError):
            Go(inputer, transformer, merger, outputer, config, \
               command_line_args = False)
Exemple #11
0
    def test_save_single_compressed(self):
        """Try saving one spill using compressed gzip
        """
        output = OutputPyJSON(gzip.GzipFile(self.tmp_file, 'w'))

        self.assertTrue(output.birth("{}"))
        output.save(self.test_string)
        self.assertTrue(output.death())
        self.assertFalse(output.save(
            self.test_string))  # attempting to write to
        # closed file

        test_doc = json.loads(self.test_string)

        my_file = gzip.GzipFile(self.tmp_file, 'r')
        read_doc = json.loads(my_file.readline())
        self.assertEqual(read_doc, test_doc)
        my_file.close()
Exemple #12
0
    def test_birth_text_format(self):
        """Test OutputPyJson loads a text file from datacards correctly."""
        output = OutputPyJSON()
        json_doc = json.dumps({
            "output_json_file_name": self.tmp_file,
            "output_json_file_type": "text"
        })
        output.birth(json_doc)
        self.assertTrue(output.save(self.test_string))
        self.assertTrue(output.death())

        my_file = open(self.tmp_file, 'r')
        read_doc = json.loads(my_file.readline())
        self.assertEqual(read_doc, json.loads(self.test_string))
        my_file.close()