Exemple #1
0
 def test_update_file_no_docstring(self):
     
     test_file_handle = PythonFileHandler(os.path.join(os.path.dirname(__file__), 'sample_tests.py'))
     metadata_dictionary_class = test_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = None)
     metadata_dictionary_class['__changed__'] = True
     
     # Add something to metadata_dictionary that wasn't there before
     metadata_dictionary_class['bugs'] = 'mpp-1'
     
     # Modify method one as well
     metadata_dictionary_method = test_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1')
     metadata_dictionary_method['__changed__'] = True
     
     # Add something to metadata_dictionary that wasn't there before
     metadata_dictionary_method['tags'] = 'smoke'
     
     new_file = os.path.join(os.path.dirname(__file__), 'sample_tests_new.py')
     test_file_handle.update_docstring(class_name = 'SampleTestsNoDocstring', method_name = None, metadata_dictionary = metadata_dictionary_class)
     test_file_handle.update_docstring(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1', metadata_dictionary = metadata_dictionary_method)
     test_file_handle.update_file(new_file)
     
     # Verify that new file exists
     self.assertTrue(os.path.exists(new_file))
     # Now, get the docstring from new file
     new_file_handle = PythonFileHandler(new_file)
     
     new_class_tuple = None
     new_method_tuple = None
     for my_tuple in new_file_handle.docstring_tuples:
         if my_tuple.class_name == 'SampleTestsNoDocstring' and my_tuple.method_name == None:
             new_class_tuple = my_tuple
         if my_tuple.class_name == 'SampleTestsNoDocstring' and my_tuple.method_name == 'test_no_1':
             new_method_tuple = my_tuple
     
     self.assertTrue(new_class_tuple is not None)
     self.assertTrue(new_method_tuple is not None)
     
     # Verify original docstring of new_file
     self.assertTrue(new_class_tuple.original_docstring is not None)
     self.assertTrue(new_method_tuple.original_docstring is not None)
     self.assertTrue("    @bugs mpp-1" in new_class_tuple.original_docstring)
     self.assertTrue("        @tags smoke" in new_method_tuple.original_docstring)
     
     # Verify that update_file in-place works
     new_class_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = None)
     new_method_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1')
     new_class_dict['__changed__'] = True
     new_method_dict['__changed__'] = True
     
     new_class_dict.pop('bugs')
     new_method_dict.pop('tags')
     
     new_file_handle.update_docstring(class_name = 'SampleTestsNoDocstring', method_name = None, metadata_dictionary = new_class_dict)
     new_file_handle.update_docstring(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1', metadata_dictionary = new_method_dict)
     new_file_handle.update_file()
     
     new_file_handle = PythonFileHandler(new_file)
     new_class_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = None)
     new_method_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1')
     # Should have no keys (except for __changed__)
     self.assertEqual(len(new_class_dict), 1)
     self.assertEqual(len(new_method_dict), 1)
     
     os.remove(new_file)
Exemple #2
0
    def test_update_file_no_docstring(self):

        test_file_handle = PythonFileHandler(
            os.path.join(os.path.dirname(__file__), 'sample_tests.py'))
        metadata_dictionary_class = test_file_handle.get_metadata_dictionary(
            class_name='SampleTestsNoDocstring', method_name=None)
        metadata_dictionary_class['__changed__'] = True

        # Add something to metadata_dictionary that wasn't there before
        metadata_dictionary_class['bugs'] = 'mpp-1'

        # Modify method one as well
        metadata_dictionary_method = test_file_handle.get_metadata_dictionary(
            class_name='SampleTestsNoDocstring', method_name='test_no_1')
        metadata_dictionary_method['__changed__'] = True

        # Add something to metadata_dictionary that wasn't there before
        metadata_dictionary_method['tags'] = 'smoke'

        new_file = os.path.join(os.path.dirname(__file__),
                                'sample_tests_new.py')
        test_file_handle.update_docstring(
            class_name='SampleTestsNoDocstring',
            method_name=None,
            metadata_dictionary=metadata_dictionary_class)
        test_file_handle.update_docstring(
            class_name='SampleTestsNoDocstring',
            method_name='test_no_1',
            metadata_dictionary=metadata_dictionary_method)
        test_file_handle.update_file(new_file)

        # Verify that new file exists
        self.assertTrue(os.path.exists(new_file))
        # Now, get the docstring from new file
        new_file_handle = PythonFileHandler(new_file)

        new_class_tuple = None
        new_method_tuple = None
        for my_tuple in new_file_handle.docstring_tuples:
            if my_tuple.class_name == 'SampleTestsNoDocstring' and my_tuple.method_name == None:
                new_class_tuple = my_tuple
            if my_tuple.class_name == 'SampleTestsNoDocstring' and my_tuple.method_name == 'test_no_1':
                new_method_tuple = my_tuple

        self.assertTrue(new_class_tuple is not None)
        self.assertTrue(new_method_tuple is not None)

        # Verify original docstring of new_file
        self.assertTrue(new_class_tuple.original_docstring is not None)
        self.assertTrue(new_method_tuple.original_docstring is not None)
        self.assertTrue(
            "    @bugs mpp-1" in new_class_tuple.original_docstring)
        self.assertTrue(
            "        @tags smoke" in new_method_tuple.original_docstring)

        # Verify that update_file in-place works
        new_class_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleTestsNoDocstring', method_name=None)
        new_method_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleTestsNoDocstring', method_name='test_no_1')
        new_class_dict['__changed__'] = True
        new_method_dict['__changed__'] = True

        new_class_dict.pop('bugs')
        new_method_dict.pop('tags')

        new_file_handle.update_docstring(class_name='SampleTestsNoDocstring',
                                         method_name=None,
                                         metadata_dictionary=new_class_dict)
        new_file_handle.update_docstring(class_name='SampleTestsNoDocstring',
                                         method_name='test_no_1',
                                         metadata_dictionary=new_method_dict)
        new_file_handle.update_file()

        new_file_handle = PythonFileHandler(new_file)
        new_class_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleTestsNoDocstring', method_name=None)
        new_method_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleTestsNoDocstring', method_name='test_no_1')
        # Should have no keys (except for __changed__)
        self.assertEqual(len(new_class_dict), 1)
        self.assertEqual(len(new_method_dict), 1)

        os.remove(new_file)
Exemple #3
0
 def test_update_file_existing_docstring(self):
     
     test_file_handle = PythonFileHandler(os.path.join(os.path.dirname(__file__), 'sample_tests.py'))
     metadata_dictionary_class = test_file_handle.get_metadata_dictionary(class_name = 'SampleSQLTests', method_name = None)
     metadata_dictionary_class['__changed__'] = True
     
     # Original author is sql_author. Change it to bal_author
     metadata_dictionary_class['author'] = "bal_author"
     # Add something to metadata_dictionary that wasn't there before
     metadata_dictionary_class['bugs'] = 'mpp-1'
     
     # Modify method one as well
     metadata_dictionary_method = test_file_handle.get_metadata_dictionary(class_name = 'SampleMPPTests', method_name = 'test_3')
     metadata_dictionary_method['__changed__'] = True
     
     # Original product_version is prod1:. Delete it.
     metadata_dictionary_method.pop('product_version')
     # Add something to metadata_dictionary that wasn't there before
     metadata_dictionary_method['tags'] = 'smoke'
     
     new_file = os.path.join(os.path.dirname(__file__), 'sample_tests_new.py')
     test_file_handle.update_docstring(class_name = 'SampleSQLTests', method_name = None, metadata_dictionary = metadata_dictionary_class)
     test_file_handle.update_docstring(class_name = 'SampleMPPTests', method_name = 'test_3', metadata_dictionary = metadata_dictionary_method)
     test_file_handle.update_file(new_file)
     
     # Verify that new file exists
     self.assertTrue(os.path.exists(new_file))
     # Now, get the docstring from new file
     new_file_handle = PythonFileHandler(new_file)
     
     new_class_tuple = None
     new_method_tuple = None
     for my_tuple in new_file_handle.docstring_tuples:
         if my_tuple.class_name == 'SampleSQLTests' and my_tuple.method_name == None:
             new_class_tuple = my_tuple
         if my_tuple.class_name == 'SampleMPPTests' and my_tuple.method_name == 'test_3':
             new_method_tuple = my_tuple
     
     self.assertTrue(new_class_tuple is not None)
     self.assertTrue(new_method_tuple is not None)
     
     # Verify original docstring of new_file
     self.assertTrue("    Comment here" in new_class_tuple.original_docstring)
     self.assertTrue("    @author bal_author" in new_class_tuple.original_docstring)
     self.assertTrue("    @bugs mpp-1" in new_class_tuple.original_docstring)
     self.assertTrue("        @tags smoke" in new_method_tuple.original_docstring)
     self.assertTrue("@product_version" not in new_method_tuple.original_docstring)
     
     # Verify that update_file in-place works
     new_class_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleSQLTests', method_name = None)
     new_method_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleMPPTests', method_name = 'test_3')
     new_class_dict['__changed__'] = True
     new_method_dict['__changed__'] = True
     
     new_class_dict.pop('author')
     new_class_dict.pop('tags')
     new_class_dict.pop('bugs')
     new_method_dict.pop('tags')
     
     new_file_handle.update_docstring(class_name = 'SampleSQLTests', method_name = None, metadata_dictionary = new_class_dict)
     new_file_handle.update_docstring(class_name = 'SampleMPPTests', method_name = 'test_3', metadata_dictionary = new_method_dict)
     new_file_handle.update_file()
     
     new_file_handle = PythonFileHandler(new_file)
     new_class_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleSQLTests', method_name = None)
     new_method_dict = new_file_handle.get_metadata_dictionary(class_name = 'SampleMPPTests', method_name = 'test_3')
     # Should have no keys (except for __changed__)
     self.assertEqual(len(new_class_dict), 1)
     self.assertEqual(len(new_method_dict), 1)
     
     os.remove(new_file)
Exemple #4
0
    def test_update_file_existing_docstring(self):

        test_file_handle = PythonFileHandler(
            os.path.join(os.path.dirname(__file__), 'sample_tests.py'))
        metadata_dictionary_class = test_file_handle.get_metadata_dictionary(
            class_name='SampleSQLTests', method_name=None)
        metadata_dictionary_class['__changed__'] = True

        # Original author is sql_author. Change it to bal_author
        metadata_dictionary_class['author'] = "bal_author"
        # Add something to metadata_dictionary that wasn't there before
        metadata_dictionary_class['bugs'] = 'mpp-1'

        # Modify method one as well
        metadata_dictionary_method = test_file_handle.get_metadata_dictionary(
            class_name='SampleMPPTests', method_name='test_3')
        metadata_dictionary_method['__changed__'] = True

        # Original product_version is prod1:. Delete it.
        metadata_dictionary_method.pop('product_version')
        # Add something to metadata_dictionary that wasn't there before
        metadata_dictionary_method['tags'] = 'smoke'

        new_file = os.path.join(os.path.dirname(__file__),
                                'sample_tests_new.py')
        test_file_handle.update_docstring(
            class_name='SampleSQLTests',
            method_name=None,
            metadata_dictionary=metadata_dictionary_class)
        test_file_handle.update_docstring(
            class_name='SampleMPPTests',
            method_name='test_3',
            metadata_dictionary=metadata_dictionary_method)
        test_file_handle.update_file(new_file)

        # Verify that new file exists
        self.assertTrue(os.path.exists(new_file))
        # Now, get the docstring from new file
        new_file_handle = PythonFileHandler(new_file)

        new_class_tuple = None
        new_method_tuple = None
        for my_tuple in new_file_handle.docstring_tuples:
            if my_tuple.class_name == 'SampleSQLTests' and my_tuple.method_name == None:
                new_class_tuple = my_tuple
            if my_tuple.class_name == 'SampleMPPTests' and my_tuple.method_name == 'test_3':
                new_method_tuple = my_tuple

        self.assertTrue(new_class_tuple is not None)
        self.assertTrue(new_method_tuple is not None)

        # Verify original docstring of new_file
        self.assertTrue(
            "    Comment here" in new_class_tuple.original_docstring)
        self.assertTrue(
            "    @author bal_author" in new_class_tuple.original_docstring)
        self.assertTrue(
            "    @bugs mpp-1" in new_class_tuple.original_docstring)
        self.assertTrue(
            "        @tags smoke" in new_method_tuple.original_docstring)
        self.assertTrue(
            "@product_version" not in new_method_tuple.original_docstring)

        # Verify that update_file in-place works
        new_class_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleSQLTests', method_name=None)
        new_method_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleMPPTests', method_name='test_3')
        new_class_dict['__changed__'] = True
        new_method_dict['__changed__'] = True

        new_class_dict.pop('author')
        new_class_dict.pop('tags')
        new_class_dict.pop('bugs')
        new_method_dict.pop('tags')

        new_file_handle.update_docstring(class_name='SampleSQLTests',
                                         method_name=None,
                                         metadata_dictionary=new_class_dict)
        new_file_handle.update_docstring(class_name='SampleMPPTests',
                                         method_name='test_3',
                                         metadata_dictionary=new_method_dict)
        new_file_handle.update_file()

        new_file_handle = PythonFileHandler(new_file)
        new_class_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleSQLTests', method_name=None)
        new_method_dict = new_file_handle.get_metadata_dictionary(
            class_name='SampleMPPTests', method_name='test_3')
        # Should have no keys (except for __changed__)
        self.assertEqual(len(new_class_dict), 1)
        self.assertEqual(len(new_method_dict), 1)

        os.remove(new_file)