Ejemplo n.º 1
0
    def test_invalid_number_of_arguments(self):
        """ If incorrect number of arguments is passed to monkey, an error code
        shall be returned. """

        mock_file = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(argparse.ArgumentParser, "_get_value")

        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(",")
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foo").AndReturn(mock_file)

        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(",")
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foo").AndReturn(mock_file)
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "bar").AndReturn(mock_file)

        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(",")
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foo").AndReturn(mock_file)
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "bar").AndReturn(mock_file)
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foobar").AndReturn(mock_file)

        self.mox.ReplayAll()

        with nostdoutstderr(): 
            self.assertEquals(2, monkey.main(["foo"]))
            self.assertEquals(2, monkey.main(["foo", "bar"]))
            self.assertEquals(2, monkey.main(["foo", "bar", "foobar"]))
Ejemplo n.º 2
0
    def test_changing_csv_separator(self):
        """ Ensure translation, when having changed CSV separator, works as
        expected. """


        self.mox.StubOutWithMock(argparse.ArgumentParser, "_get_value")

        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(".")
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(".")
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foo").AndReturn(self.__header)
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "bar").AndReturn(self.__footer)
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foobar").AndReturn(self.__template)
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foobaz").AndReturn(
                                               self.__csv_dot_separator)
        self.mox.ReplayAll()

        with stdoutcomparator(self, self.__expected_output_simple):
            self.assertEquals(0,
                              monkey.main(self.__monkey_args_changed_separator))
Ejemplo n.º 3
0
    def test_simple_translation(self):
        """ Ensure that a basic CSV translation works as expected. """

        self.mock_reading_files(self.__monkey_args,
                                self.__template)

        self.mox.ReplayAll()

        with stdoutcomparator(self, self.__expected_output_simple):
            self.assertEquals(0, monkey.main(self.__monkey_args))
Ejemplo n.º 4
0
    def test_translation_duplicate_indedxes(self):
        """ Duplicated indexes in the template file should be accepted. """


        self.mock_reading_files(self.__monkey_args,
                                self.__template_duplicated_index)

        self.mox.ReplayAll()

        with stdoutcomparator(self, self.__expected_output_duplicated):
            self.assertEquals(0, monkey.main(self.__monkey_args))
Ejemplo n.º 5
0
    def test_failing_to_open_header_file(self):
        """ If monkey fails to open the header file, an error code shall be
        returned. """

        self.mox.StubOutWithMock(argparse.ArgumentParser, "_get_value")

        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(",")
        argparse.ArgumentParser._get_value(mox.IgnoreArg(),
                                           "foo").AndRaise(IOError)

        self.mox.ReplayAll()

        with nostdoutstderr():
            self.assertEquals(128, monkey.main(self.__monkey_args))
Ejemplo n.º 6
0
    def test_full_line_comments(self):

        template_with_multiline_comments = StringIO(
                """# this is a multiline comment, which should be ignore
# .. and so should this one
%1% and %2%
# .. as well as this one.""")

        expected_output_when_multiline_comments = "%sFIRST and SECOND\n%s\n" % \
                (self.__header.getvalue(), self.__footer.getvalue())


        self.mock_reading_files(self.__monkey_args,
                                template_with_multiline_comments)

        self.mox.ReplayAll()

        with stdoutcomparator(self, expected_output_when_multiline_comments):
            self.assertEquals(0, monkey.main(self.__monkey_args))
Ejemplo n.º 7
0
    def test_help_command(self):
        """ Make sure that the help flags are accepted. """

        with nostdoutstderr():
            self.assertEquals(0, monkey.main(["-h"]))
            self.assertEquals(0, monkey.main(["--help"]))