Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pythonize run_unit_tests.sh #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions run_unit_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'''
This helper script for Seattle testbed, https://seattle.poly.edu/,
* downloads Seattle testbed's sources from GitHub,
* builds them using Seattle's build scripts, and finally
* runs Seattle's unit tests.

Find documentation for Seattle's build scripts and unit test framework at
https://seattle.poly.edu/wiki/BuildInstructions
https://seattle.poly.edu/wiki/UnitTestFramework

The list of components (i.e. source repositories) for which the
tests are run is configurable via the repolist variable, see below.

Since other testbeds use the Seattle codebase, we make the testbed
name (and thus repo address) configurable too:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation says that repolist and testbed are configurable. It appears that they must modified directly in the code. Does it make sense to make them configurable from the command-line?

'''
import os
import sys
import subprocess
import time
import string

def main():
testbed = 'Seattletestbed'
# If you like to test the complete set of repos, get the list of
# $testbed repositories via the GitHub API, grab entries like
# "full_name": "Seattletestbed/foo",
# cut out the repo names, and create a space-separated list:
#
# repolist=`curl https://api.github.com/orgs/$testbed/repos | awk '/full_name/ {gsub("\"", ""); gsub(",", ""); split($2, a, "/"); printf a[2] " "}'`


# Otherwise, just supply the list yourself.
#
# Here's a mostly complete one, omitting but a few backup/outdated repos:
# repolist="advertiseserver affix buildscripts common demokit experimentmanager geoip_server nodemanager overlord portability repy_v1 repy_v2 seash seattlelib_v1 seattlelib_v2 softwareupdater timeserver utf zenodotus"

# This is the "bare minimum" list. Whatever changes you make to the
# Seattle codebase, do make sure these tests pass (in addition to the
# repo you changed, of course!)
repolist = ["common", "nodemanager", "repy_v2", "seattlelib_v2", "seash", "softwareupdater", "utf"]
for repo in repolist:
print "Running tests for this list of "+ testbed +"\'s repositories: " + repo

# We will also measure the time elapsed for all tests
test_suite_started_at = time.time()

# For every repo name, ...
for repo in repolist:
print "Testing " + testbed + '/' + repo + " now..."
print "https://github.com/" + testbed + "/" + repo + ".git"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the domain name configurable, too? For example, if a local or non-github git repository is needed.

# Clone the repo
subprocess.call(["git", "clone","https://github.com/" + testbed + "/" + repo + ".git"])

# If $repo has a "tests" subdir, then prepare the
# test files and run the tests
if os.path.isdir(repo +os.path.sep +"tests"):
# Measure the time for this single repo's tests
repo_test_started_at = time.time()
os.chdir(repo + os.path.sep +"scripts")
subprocess.call([sys.executable, "initialize.py"])
subprocess.call([sys.executable, "build.py", "-t"])
os.chdir(".." + os.path.sep +"RUNNABLE")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why os.path.join() isn't used?

subprocess.call([sys.executable, "utf.py", "-a"])
repo_test_finished_at = time.time()
repo_test_time = str(repo_test_finished_at - repo_test_started_at)
print "Tests for " + testbed + "/" + repo + " took " + repo_test_time + " seconds, excluding download and build"
os.chdir(".." + os.path.sep + "..")
else:
print testbed + "/" + repo + "has no \"tests\" directory. Skipping."

test_suite_finished_at = time.time()
test_suite_time = str(test_suite_finished_at - test_suite_started_at)
print "Done running tests for " + testbed + ", which took me " + test_suite_time + " seconds overall."

if __name__ == '__main__':
main()