Commits

Anonymous committed 718efdb

Use clean repositories (just initialized and the files added, without any changes) for each run.

Comments (0)

Files changed (1)

distributed_version_control_system_test.py

     
     return test_results
 
+
 def test_init(number_of_tests=10):
     """Test initiating a repository."""
     # Now we initialize the repository over the general_test_function. 
     print "Init results: [git, hg]", mean(results)
     # And return it. 
     return mean(results)
-    
+
+
 def test_initial_commit(number_of_tests=10):
     """Test the initial commit. Must come after test_init."""
     # Then we commit all files
-    results = multiple_tests(number_of_tests, [init_add_and_commit_git, init_add_and_commit_hg])
+    results = armored_tests([init_add_and_commit_git, init_add_and_commit_hg], first=[backup_repo_git, backup_repo_hg], before=[undo_git, undo_hg], number_of_tests=number_of_tests)
 
     # print the result
     print "Initial commit results: [git, hg]", mean(results)
     # and return it. 
     return mean(results)
 
+
 def test_append_small(data, number_of_tests=10):
     """Append a short line to each file and commit."""
     # Now we need to append stuff to the files. We just use the filename + the same data . 
         f = open(str(i[0]), "a")
         f.write(str(i[0]) + str(i[1]))
         f.close()
-    # Now we use a test armored by restoring the repo before each run. 
-    # But first we need a backup. 
-    backup_repo_git()
-    backup_repo_hg()
+    
+    # Now we use a test armored by restoring the repo before each run. We just use the backup from the previous test, so our backup doesn't get too large. 
     results = armored_tests([commit_git, commit_hg], before=[undo_git, undo_hg], number_of_tests=number_of_tests)
     # Print the result
     print "Commit results after append: [git, hg]", mean(results)
     # And return it
     return mean(results)
 
+
 def test_append_many_lines(data, number_of_tests=10):
     """Test the speed of Mercurial and git when appending a large amount of data. """
     # We test what happens if we add the same data to each file, but lots of it. 
         for j in data: 
             f.write(str(j))
         f.close
-    # Now we use a test armored by restoring the repo before each run. 
-    # But first we need a backup. 
-    backup_repo_git()
-    backup_repo_hg()
+    
+    # Now we use a test armored by restoring the repo before each run. We just use the backup from the previous test, so our backup doesn't get too large. 
     results = armored_tests([commit_git, commit_hg], before=[undo_git, undo_hg], number_of_tests=number_of_tests)
     # Print our result
     print "Commit results after append of same big data: [git, hg]", mean(results)
     # And return it
     return mean(results)
 
+
 def test_append_one_long_line(data, number_of_tests=10):
     """Test the speed of Mercurial and git when appending a large amount of data. """
     # We test what happens if we add the same data to each file, but lots of it. 
         f = open(str(i[0]), "a")
         f.write(str(data)*100)
         f.close
-    # Now we use a test armored by restoring the repo before each run. 
-    # But first we need a backup. 
-    backup_repo_git()
-    backup_repo_hg()
+        
+    # Now we use a test armored by restoring the repo before each run. We just use the backup from the previous test, so our backup doesn't get too large. 
     results = armored_tests([commit_git, commit_hg], before=[undo_git, undo_hg], number_of_tests=number_of_tests)
     # Print our result
     print "Commit results after append of same big data: [git, hg]", mean(results)
     # And return it
     return mean(results)
 
-def armored_tests(function_list, before=None, after=None, number_of_tests=10):
-    """Run many tests, each armored by a list of functions which are called before the main function, and by one which are called after it."""
+
+def armored_tests(function_list, first=None, before=None, after=None, number_of_tests=10):
+    """Run many tests, each armored by a list of functions which are called before the main function, and by one which are called after it.
+    
+    @param first: functions that run before any tests and only once. 
+    @param last: Functions that run after all tests and only once. 
+    """
     # We need to add some handywork, here. 
+    
+    # First run all first functions. 
+    if first is not None: 
+        for i in first: 
+            i()
+    
     # First an empty list to which we will add the results. 
     results = []
     # Then we'll do the runs one after the other. 
     # Add all files
     shellcall("git add *")
     # And commit
-    shellcall("git commit -m 'test'")
+    shellcall("git commit -a -m 'test'")
     
 def backup_repo_git(*args):
     """Create a backup of the git directory, named .git.bak ."""    
 
 def undo_git(*args):
     """Delete and then restore the git dir from backup. """
-    # Reset the repo
-    shellcall("git reset")
+    print "undo git"
+    # Delete the repo
+    shellcall("rm -Rf .git")
+    # And copy it from the backup
+    shellcall("cp -Rf .git.bak/ .git")
 
 def init_hg(*args): 
     """Initialize a Mercurial repository."""
     shellcall("cp -Rf .hg .hg.bak")
 
 def undo_hg(*args):
-    """Delete and then restore the hg dir from backup. """
+    """Just rollback the last commit. """
     # Rollback the repo
     shellcall("hg rollback")