Exemplo n.º 1
0
    def test_update_docstring_existing(self):

        # Query01 (scenario that has some docstring)
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql', 'query01.sql'))
        self.assertTrue(test_file_handle.original_docstring)
        my_dict = test_file_handle.get_metadata_dictionary()
        my_dict['__changed__'] = True

        # Change original tags to smoke
        my_dict['tags'] = 'smoke'
        # Remove bugs
        my_dict.pop('bugs')
        # Add author
        my_dict['author'] = 'blah'

        test_file_handle.update_docstring(my_dict)

        # Verify that new_docstring exists
        self.assertTrue(test_file_handle.new_docstring)
        # Verify that tags is updated
        self.assertTrue("@tags smoke" in test_file_handle.new_docstring)
        # Verify that bugs is removed
        self.assertTrue('@bugs' not in test_file_handle.new_docstring)
        # Verify that author is added
        self.assertTrue('@author blah' in test_file_handle.new_docstring)
        # Verify that the comment is still there
        self.assertTrue('-- comment' in test_file_handle.new_docstring)
Exemplo n.º 2
0
 def test_update_docstring_existing(self):
     
     # Query01 (scenario that has some docstring)
     test_file_handle = SQLFileHandler(os.path.join(os.path.dirname(__file__), 'sql', 'query01.sql'))
     self.assertTrue(test_file_handle.original_docstring)
     my_dict = test_file_handle.get_metadata_dictionary()
     my_dict['__changed__'] = True
     
     # Change original tags to smoke
     my_dict['tags'] = 'smoke'
     # Remove bugs
     my_dict.pop('bugs')
     # Add author
     my_dict['author'] = 'blah'
     
     test_file_handle.update_docstring(my_dict)
     
     # Verify that new_docstring exists
     self.assertTrue(test_file_handle.new_docstring)
     # Verify that tags is updated
     self.assertTrue("@tags smoke" in test_file_handle.new_docstring)
     # Verify that bugs is removed
     self.assertTrue('@bugs' not in test_file_handle.new_docstring)
     # Verify that author is added
     self.assertTrue('@author blah' in test_file_handle.new_docstring)
     # Verify that the comment is still there
     self.assertTrue('-- comment' in test_file_handle.new_docstring)
Exemplo n.º 3
0
    def test_parser(self):
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql', 'query01.sql'))

        # Check that docstring is not empty
        self.assertTrue(test_file_handle.original_docstring)

        # Verify that the original docstring is correct
        self.assertTrue("-- @tags tag1 tag2 tag3 bug-3" in
                        test_file_handle.original_docstring)
        self.assertTrue("-- comment" in test_file_handle.original_docstring)
        self.assertTrue("--@bugs MPP-1" in test_file_handle.original_docstring)

        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql', 'query02.sql'))
        # Check that docstring is not empty
        self.assertTrue(test_file_handle.original_docstring)

        # Verify that the original docstring is correct
        self.assertTrue(
            "-- @product_version gpdb:" in test_file_handle.original_docstring)

        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql',
                         'query_nodocstring.sql'))
        # Check that docstring is empty
        self.assertTrue(test_file_handle.original_docstring is "")
Exemplo n.º 4
0
    def test_get_metadata_dictionary(self):

        # All dictionaries will always have __changed__ key

        # query01 has tags and bugs
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql', 'query01.sql'))
        self.assertTrue(test_file_handle.original_docstring)
        my_dict = test_file_handle.get_metadata_dictionary()
        self.assertEqual(len(my_dict), 3)
        self.assertEqual(my_dict['tags'], "tag1 tag2 tag3 bug-3")
        self.assertEqual(my_dict['bugs'], "MPP-1")

        # query02 has product_version
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql', 'query02.sql'))
        self.assertTrue(test_file_handle.original_docstring)
        my_dict = test_file_handle.get_metadata_dictionary()
        self.assertEqual(len(my_dict), 2)
        self.assertEqual(my_dict['product_version'], "gpdb:")

        # query_nodocstring has nothing
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql',
                         'query_nodocstring.sql'))
        self.assertTrue(test_file_handle.original_docstring == "")
        my_dict = test_file_handle.get_metadata_dictionary()
        self.assertEqual(len(my_dict), 1)
Exemplo n.º 5
0
 def test_update_docstring_new(self):
     
     # Query01 (scenario that has some docstring)
     test_file_handle = SQLFileHandler(os.path.join(os.path.dirname(__file__), 'sql', 'query_nodocstring.sql'))
     self.assertTrue(test_file_handle.original_docstring == "")
     my_dict = test_file_handle.get_metadata_dictionary()
     my_dict['__changed__'] = True
     
     # Add tags 
     my_dict['tags'] = 'smoke'
     # Add author
     my_dict['author'] = 'blah'
     
     test_file_handle.update_docstring(my_dict)
     
     # Verify that new_docstring exists
     self.assertTrue(test_file_handle.new_docstring)
     # Verify that tags is added
     self.assertTrue("@tags smoke" in test_file_handle.new_docstring)
     # Verify that author is added
     self.assertTrue('@author blah' in test_file_handle.new_docstring)
Exemplo n.º 6
0
    def test_update_docstring_new(self):

        # Query01 (scenario that has some docstring)
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql',
                         'query_nodocstring.sql'))
        self.assertTrue(test_file_handle.original_docstring == "")
        my_dict = test_file_handle.get_metadata_dictionary()
        my_dict['__changed__'] = True

        # Add tags
        my_dict['tags'] = 'smoke'
        # Add author
        my_dict['author'] = 'blah'

        test_file_handle.update_docstring(my_dict)

        # Verify that new_docstring exists
        self.assertTrue(test_file_handle.new_docstring)
        # Verify that tags is added
        self.assertTrue("@tags smoke" in test_file_handle.new_docstring)
        # Verify that author is added
        self.assertTrue('@author blah' in test_file_handle.new_docstring)
Exemplo n.º 7
0
 def test_get_metadata_dictionary(self):
     
     # All dictionaries will always have __changed__ key
     
     # query01 has tags and bugs
     test_file_handle = SQLFileHandler(os.path.join(os.path.dirname(__file__), 'sql', 'query01.sql'))
     self.assertTrue(test_file_handle.original_docstring)
     my_dict = test_file_handle.get_metadata_dictionary()
     self.assertEqual(len(my_dict), 3)
     self.assertEqual(my_dict['tags'], "tag1 tag2 tag3 bug-3")
     self.assertEqual(my_dict['bugs'], "MPP-1")
     
     # query02 has product_version
     test_file_handle = SQLFileHandler(os.path.join(os.path.dirname(__file__), 'sql', 'query02.sql'))
     self.assertTrue(test_file_handle.original_docstring)
     my_dict = test_file_handle.get_metadata_dictionary()
     self.assertEqual(len(my_dict), 2)
     self.assertEqual(my_dict['product_version'], "gpdb:")
     
     # query_nodocstring has nothing
     test_file_handle = SQLFileHandler(os.path.join(os.path.dirname(__file__), 'sql', 'query_nodocstring.sql'))
     self.assertTrue(test_file_handle.original_docstring == "")
     my_dict = test_file_handle.get_metadata_dictionary()
     self.assertEqual(len(my_dict), 1)
Exemplo n.º 8
0
 def test_update_file_no_docstring(self):
     # Query01 (scenario that has some docstring)
     test_file_handle = SQLFileHandler(os.path.join(os.path.dirname(__file__), 'sql', 'query_nodocstring.sql'))
     self.assertTrue(test_file_handle.original_docstring == "")
     my_dict = test_file_handle.get_metadata_dictionary()
     my_dict['__changed__'] = True
     
     # Add tags 
     my_dict['tags'] = 'smoke'
     # Add author
     my_dict['author'] = 'blah'
     
     new_file = os.path.join(os.path.dirname(__file__), 'sql', 'query_nodocstring_new.sql')
     test_file_handle.update_docstring(my_dict)
     test_file_handle.update_file(new_file)
     
     # Verify that new file exists
     self.assertTrue(os.path.exists(new_file))
     # Now, get the metadata dictionary from new file
     new_file_handle = SQLFileHandler(new_file)
     self.assertTrue(new_file_handle.original_docstring)
     new_dict = new_file_handle.get_metadata_dictionary()
     # Verify the new metadata in new_dict's original_docstring
     # Verify that tags is added
     self.assertTrue("@tags smoke" in new_file_handle.original_docstring)
     # Verify that author is added
     self.assertTrue('@author blah' in new_file_handle.original_docstring)
     
     # Verify that all metadata can be removed and update_file in-place works
     new_dict['__changed__'] = True
     new_dict.pop('tags')
     new_dict.pop('author')
     
     new_file_handle.update_docstring(new_dict)
     new_file_handle.update_file()
     
     # Get the file content
     new_file_content = None
     with open(new_file, "r") as new_file_object:
         new_file_content = new_file_object.read().replace('\n', '')
     
     self.assertTrue(new_file_content is not None)
     self.assertTrue('tags' not in new_file_content)
     self.assertTrue('author' not in new_file_content)
     self.assertTrue('--' not in new_file_content)
     
     os.remove(new_file)
Exemplo n.º 9
0
    def test_update_file_no_docstring(self):
        # Query01 (scenario that has some docstring)
        test_file_handle = SQLFileHandler(
            os.path.join(os.path.dirname(__file__), 'sql',
                         'query_nodocstring.sql'))
        self.assertTrue(test_file_handle.original_docstring == "")
        my_dict = test_file_handle.get_metadata_dictionary()
        my_dict['__changed__'] = True

        # Add tags
        my_dict['tags'] = 'smoke'
        # Add author
        my_dict['author'] = 'blah'

        new_file = os.path.join(os.path.dirname(__file__), 'sql',
                                'query_nodocstring_new.sql')
        test_file_handle.update_docstring(my_dict)
        test_file_handle.update_file(new_file)

        # Verify that new file exists
        self.assertTrue(os.path.exists(new_file))
        # Now, get the metadata dictionary from new file
        new_file_handle = SQLFileHandler(new_file)
        self.assertTrue(new_file_handle.original_docstring)
        new_dict = new_file_handle.get_metadata_dictionary()
        # Verify the new metadata in new_dict's original_docstring
        # Verify that tags is added
        self.assertTrue("@tags smoke" in new_file_handle.original_docstring)
        # Verify that author is added
        self.assertTrue('@author blah' in new_file_handle.original_docstring)

        # Verify that all metadata can be removed and update_file in-place works
        new_dict['__changed__'] = True
        new_dict.pop('tags')
        new_dict.pop('author')

        new_file_handle.update_docstring(new_dict)
        new_file_handle.update_file()

        # Get the file content
        new_file_content = None
        with open(new_file, "r") as new_file_object:
            new_file_content = new_file_object.read().replace('\n', '')

        self.assertTrue(new_file_content is not None)
        self.assertTrue('tags' not in new_file_content)
        self.assertTrue('author' not in new_file_content)
        self.assertTrue('--' not in new_file_content)

        os.remove(new_file)