~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to tests/test.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2013-05-10 23:38:14 UTC
  • mfrom: (1.1.10) (14.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130510233814-701dvlop7xfh88i7
Tags: 2.9.2-1
New upstream release (Closes: #700743).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
21
# IN THE SOFTWARE.
22
22
 
23
 
"""
24
 
do the unit tests!
25
 
"""
26
 
 
27
23
import logging
28
24
import sys
29
25
import unittest
30
 
import getopt
31
 
 
32
 
from sqs.test_connection import SQSConnectionTest
33
 
from s3.test_connection import S3ConnectionTest
34
 
from s3.test_versioning import S3VersionTest
35
 
from s3.test_mfa import S3MFATest
36
 
from s3.test_encryption import S3EncryptionTest
37
 
from s3.test_bucket import S3BucketTest
38
 
from s3.test_key import S3KeyTest
39
 
from s3.test_multidelete import S3MultiDeleteTest
40
 
from s3.test_multipart import S3MultiPartUploadTest
41
 
from s3.test_gsconnection import GSConnectionTest
42
 
from s3.test_https_cert_validation import CertValidationTest
43
 
from ec2.test_connection import EC2ConnectionTest
44
 
from ec2.elb.test_connection import ELBConnectionTest
45
 
from ec2.cloudwatch.test_connection import CloudWatchConnectionTest
46
 
from autoscale.test_connection import AutoscaleConnectionTest
47
 
from sdb.test_connection import SDBConnectionTest
48
 
from cloudfront.test_signed_urls import CloudfrontSignedUrlsTest
49
 
from dynamodb.test_layer1 import DynamoDBLayer1Test
50
 
from dynamodb.test_layer2 import DynamoDBLayer2Test
51
 
from sts.test_session_token import SessionTokenTest
52
 
 
53
 
def usage():
54
 
    print "test.py  [-t testsuite] [-v verbosity]"
55
 
    print "    -t   run specific testsuite (s3|ssl|s3mfa|gs|sqs|ec2|sdb|dynamodb|dynamodbL1|dynamodbL2|sts|all)"
56
 
    print "    -v   verbosity (0|1|2)"
 
26
 
 
27
from nose.core import run
 
28
import argparse
 
29
 
57
30
 
58
31
def main():
59
 
    try:
60
 
        opts, args = getopt.getopt(sys.argv[1:], "ht:v:",
61
 
                                   ["help", "testsuite", "verbosity"])
62
 
    except:
63
 
        usage()
64
 
        sys.exit(2)
65
 
    testsuite = "all"
66
 
    verbosity = 1
67
 
    for o, a in opts:
68
 
        if o in ("-h", "--help"):
69
 
            usage()
70
 
            sys.exit()
71
 
        if o in ("-t", "--testsuite"):
72
 
            testsuite = a
73
 
        if o in ("-v", "--verbosity"):
74
 
            verbosity = int(a)
75
 
    if len(args) != 0:
76
 
        usage()
77
 
        sys.exit()
78
 
    try:
79
 
        tests = suite(testsuite)
80
 
    except ValueError:
81
 
        usage()
82
 
        sys.exit()
83
 
    if verbosity > 1:
84
 
        logging.basicConfig(level=logging.DEBUG)
85
 
    unittest.TextTestRunner(verbosity=verbosity).run(tests)
86
 
 
87
 
def suite(testsuite="all"):
88
 
    tests = unittest.TestSuite()
89
 
    if testsuite == "all":
90
 
        tests.addTest(unittest.makeSuite(SQSConnectionTest))
91
 
        tests.addTest(unittest.makeSuite(S3ConnectionTest))
92
 
        tests.addTest(unittest.makeSuite(EC2ConnectionTest))
93
 
        tests.addTest(unittest.makeSuite(SDBConnectionTest))
94
 
        tests.addTest(unittest.makeSuite(AutoscaleConnectionTest))
95
 
        tests.addTest(unittest.makeSuite(CloudfrontSignedUrlsTest))
96
 
        tests.addTest(unittest.makeSuite(DynamoDBLayer1Test))
97
 
        tests.addTest(unittest.makeSuite(DynamoDBLayer2Test))
98
 
    elif testsuite == "s3":
99
 
        tests.addTest(unittest.makeSuite(S3ConnectionTest))
100
 
        tests.addTest(unittest.makeSuite(S3BucketTest))
101
 
        tests.addTest(unittest.makeSuite(S3KeyTest))
102
 
        tests.addTest(unittest.makeSuite(S3MultiPartUploadTest))
103
 
        tests.addTest(unittest.makeSuite(S3VersionTest))
104
 
        tests.addTest(unittest.makeSuite(S3EncryptionTest))
105
 
        tests.addTest(unittest.makeSuite(S3MultiDeleteTest))
106
 
    elif testsuite == "ssl":
107
 
        tests.addTest(unittest.makeSuite(CertValidationTest))
108
 
    elif testsuite == "s3mfa":
109
 
        tests.addTest(unittest.makeSuite(S3MFATest))
110
 
    elif testsuite == "gs":
111
 
        tests.addTest(unittest.makeSuite(GSConnectionTest))
112
 
    elif testsuite == "sqs":
113
 
        tests.addTest(unittest.makeSuite(SQSConnectionTest))
114
 
    elif testsuite == "ec2":
115
 
        tests.addTest(unittest.makeSuite(EC2ConnectionTest))
116
 
        tests.addTest(unittest.makeSuite(AutoscaleConnectionTest))
117
 
        tests.addTest(unittest.makeSuite(ELBConnectionTest))
118
 
        tests.addTest(unittest.makeSuite(CloudWatchConnectionTest))
119
 
    elif testsuite == "autoscale":
120
 
        tests.addTest(unittest.makeSuite(AutoscaleConnectionTest))
121
 
    elif testsuite == "sdb":
122
 
        tests.addTest(unittest.makeSuite(SDBConnectionTest))
123
 
    elif testsuite == "cloudfront":
124
 
        tests.addTest(unittest.makeSuite(CloudfrontSignedUrlsTest))
125
 
    elif testsuite == "dynamodb":
126
 
        tests.addTest(unittest.makeSuite(DynamoDBLayer1Test))
127
 
        tests.addTest(unittest.makeSuite(DynamoDBLayer2Test))
128
 
    elif testsuite == "dynamodbL1":
129
 
        tests.addTest(unittest.makeSuite(DynamoDBLayer1Test))
130
 
    elif testsuite == "dynamodbL2":
131
 
        tests.addTest(unittest.makeSuite(DynamoDBLayer2Test))
132
 
    elif testsuite == "sts":
133
 
        tests.addTest(unittest.makeSuite(SessionTokenTest))
 
32
    description = ("Runs boto unit and/or integration tests. "
 
33
                   "Arguments will be passed on to nosetests. "
 
34
                   "See nosetests --help for more information.")
 
35
    parser = argparse.ArgumentParser(description=description)
 
36
    parser.add_argument('-t', '--service-tests', action="append", default=[],
 
37
                        help="Run tests for a given service.  This will "
 
38
                        "run any test tagged with the specified value, "
 
39
                        "e.g -t s3 -t ec2")
 
40
    known_args, remaining_args = parser.parse_known_args()
 
41
    attribute_args = []
 
42
    for service_attribute in known_args.service_tests:
 
43
        attribute_args.extend(['-a', '!notdefault,' +service_attribute])
 
44
    if not attribute_args:
 
45
        # If the user did not specify any filtering criteria, we at least
 
46
        # will filter out any test tagged 'notdefault'.
 
47
        attribute_args = ['-a', '!notdefault']
 
48
    all_args = [__file__] + attribute_args + remaining_args
 
49
    print "nose command:", ' '.join(all_args)
 
50
    if run(argv=all_args):
 
51
        # run will return True is all the tests pass.  We want
 
52
        # this to equal a 0 rc
 
53
        return 0
134
54
    else:
135
 
        raise ValueError("Invalid choice.")
136
 
    return tests
 
55
        return 1
 
56
 
137
57
 
138
58
if __name__ == "__main__":
139
 
    main()
 
59
    sys.exit(main())