def test_update_docstring_class(self): test_file_handle = PythonFileHandler(os.path.join(os.path.dirname(__file__), 'sample_tests.py')) metadata_dictionary = test_file_handle.get_metadata_dictionary(class_name = 'SampleSQLTests', method_name = None) metadata_dictionary['__changed__'] = True # Original author is sql_author. Change it to bal_author metadata_dictionary['author'] = "bal_author" # Add something to metadata_dictionary that wasn't there before metadata_dictionary['bugs'] = 'mpp-1' test_file_handle.update_docstring(class_name = 'SampleSQLTests', method_name = None, metadata_dictionary = metadata_dictionary) # Go through the docstring_tuples and find our tuple tuple_found = None for my_tuple in test_file_handle.docstring_tuples: if my_tuple.class_name == 'SampleSQLTests' and my_tuple.method_name == None: tuple_found = my_tuple break self.assertTrue(tuple_found is not None) self.assertTrue("@author bal_author" in tuple_found.new_docstring) self.assertTrue("@author sql_author" not in tuple_found.new_docstring) # Verify that the comment is still there self.assertTrue("Comment here" in tuple_found.new_docstring) self.assertTrue("Some space above" in tuple_found.new_docstring) # Verify that new metadata got added with 4 spaces self.assertTrue(" @bugs mpp-1" in tuple_found.new_docstring)
def test_update_docstring_no_original_method(self): test_file_handle = PythonFileHandler( os.path.join(os.path.dirname(__file__), 'sample_tests.py')) metadata_dictionary = test_file_handle.get_metadata_dictionary( class_name='SampleTestsNoDocstring', method_name='test_no_1') metadata_dictionary['__changed__'] = True # Add something to metadata_dictionary that wasn't there before metadata_dictionary['bugs'] = 'mpp-4' metadata_dictionary['tags'] = 'smokey' test_file_handle.update_docstring( class_name='SampleTestsNoDocstring', method_name='test_no_1', metadata_dictionary=metadata_dictionary) # Go through the docstring_tuples and find our tuple tuple_found = None for my_tuple in test_file_handle.docstring_tuples: if my_tuple.class_name == 'SampleTestsNoDocstring' and my_tuple.method_name == 'test_no_1': tuple_found = my_tuple break self.assertTrue(tuple_found is not None) # Verify that new metadata got added with 4 spaces for class self.assertTrue(" @bugs mpp-4" in tuple_found.new_docstring) self.assertTrue(" @tags smokey" in tuple_found.new_docstring) self.assertTrue(tuple_found.original_docstring is None)
def test_update_docstring_method(self): test_file_handle = PythonFileHandler( os.path.join(os.path.dirname(__file__), 'sample_tests.py')) metadata_dictionary = test_file_handle.get_metadata_dictionary( class_name='SampleSQLTests', method_name="test_explicit_2") metadata_dictionary['__changed__'] = True # Add something to metadata_dictionary that wasn't there before metadata_dictionary['bugs'] = 'mpp-2' test_file_handle.update_docstring( class_name='SampleSQLTests', method_name='test_explicit_2', metadata_dictionary=metadata_dictionary) # Go through the docstring_tuples and find our tuple tuple_found = None for my_tuple in test_file_handle.docstring_tuples: if my_tuple.class_name == 'SampleSQLTests' and my_tuple.method_name == 'test_explicit_2': tuple_found = my_tuple break self.assertTrue(tuple_found is not None) # Verify that new metadata got added with 8 spaces for method self.assertTrue(" @bugs mpp-2" in tuple_found.new_docstring)
def test_update_docstring_class(self): test_file_handle = PythonFileHandler( os.path.join(os.path.dirname(__file__), 'sample_tests.py')) metadata_dictionary = test_file_handle.get_metadata_dictionary( class_name='SampleSQLTests', method_name=None) metadata_dictionary['__changed__'] = True # Original author is sql_author. Change it to bal_author metadata_dictionary['author'] = "bal_author" # Add something to metadata_dictionary that wasn't there before metadata_dictionary['bugs'] = 'mpp-1' test_file_handle.update_docstring( class_name='SampleSQLTests', method_name=None, metadata_dictionary=metadata_dictionary) # Go through the docstring_tuples and find our tuple tuple_found = None for my_tuple in test_file_handle.docstring_tuples: if my_tuple.class_name == 'SampleSQLTests' and my_tuple.method_name == None: tuple_found = my_tuple break self.assertTrue(tuple_found is not None) self.assertTrue("@author bal_author" in tuple_found.new_docstring) self.assertTrue("@author sql_author" not in tuple_found.new_docstring) # Verify that the comment is still there self.assertTrue("Comment here" in tuple_found.new_docstring) self.assertTrue("Some space above" in tuple_found.new_docstring) # Verify that new metadata got added with 4 spaces self.assertTrue(" @bugs mpp-1" in tuple_found.new_docstring)
def test_update_docstring_method(self): test_file_handle = PythonFileHandler(os.path.join(os.path.dirname(__file__), 'sample_tests.py')) metadata_dictionary = test_file_handle.get_metadata_dictionary(class_name = 'SampleSQLTests', method_name = "test_explicit_2") metadata_dictionary['__changed__'] = True # Add something to metadata_dictionary that wasn't there before metadata_dictionary['bugs'] = 'mpp-2' test_file_handle.update_docstring(class_name = 'SampleSQLTests', method_name = 'test_explicit_2', metadata_dictionary = metadata_dictionary) # Go through the docstring_tuples and find our tuple tuple_found = None for my_tuple in test_file_handle.docstring_tuples: if my_tuple.class_name == 'SampleSQLTests' and my_tuple.method_name == 'test_explicit_2': tuple_found = my_tuple break self.assertTrue(tuple_found is not None) # Verify that new metadata got added with 8 spaces for method self.assertTrue(" @bugs mpp-2" in tuple_found.new_docstring)
def test_update_docstring_no_original_method(self): test_file_handle = PythonFileHandler(os.path.join(os.path.dirname(__file__), 'sample_tests.py')) metadata_dictionary = test_file_handle.get_metadata_dictionary(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1') metadata_dictionary['__changed__'] = True # Add something to metadata_dictionary that wasn't there before metadata_dictionary['bugs'] = 'mpp-4' metadata_dictionary['tags'] = 'smokey' test_file_handle.update_docstring(class_name = 'SampleTestsNoDocstring', method_name = 'test_no_1', metadata_dictionary = metadata_dictionary) # Go through the docstring_tuples and find our tuple tuple_found = None for my_tuple in test_file_handle.docstring_tuples: if my_tuple.class_name == 'SampleTestsNoDocstring' and my_tuple.method_name == 'test_no_1': tuple_found = my_tuple break self.assertTrue(tuple_found is not None) # Verify that new metadata got added with 4 spaces for class self.assertTrue(" @bugs mpp-4" in tuple_found.new_docstring) self.assertTrue(" @tags smokey" in tuple_found.new_docstring) self.assertTrue(tuple_found.original_docstring is None)
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)
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)
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)
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)