Package yakumo :: Module smoketest
[hide private]
[frames] | no frames]

Source Code for Module yakumo.smoketest

 1  #!/usr/bin/python 
 2  # 
 3  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>. 
 4  # All Rights Reserved. 
 5  # 
 6  #    Licensed under the Apache License, Version 2.0 (the "License"); you may 
 7  #    not use this file except in compliance with the License. You may obtain 
 8  #    a copy of the License at 
 9  # 
10  #         http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  #    Unless required by applicable law or agreed to in writing, software 
13  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
14  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
15  #    License for the specific language governing permissions and limitations 
16  #    under the License. 
17   
18   
19  import logging 
20  import os.path 
21  import random 
22  import sys 
23   
24  from yakumo import Client, utils 
25   
26   
27  __all__ = ('LOG', 'get_random_str', 'test', 'show_test_summary') 
28   
29  SOURCE = "abcdefghijklmnopqrstuvwxyz" \ 
30           "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ 
31           "0123456789" 
32   
33  TEST_LOGS = [] 
34   
35   
36  LOG = logging.getLogger(os.path.basename(sys.argv[0])) 
37  LOG.setLevel(logging.DEBUG) 
38  ch = logging.StreamHandler() 
39  ch.setLevel(logging.DEBUG) 
40  formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s') 
41  ch.setFormatter(formatter) 
42  LOG.addHandler(ch) 
43   
44   
45 -def get_random_str(prefix="test"):
46 return prefix + "-" + "".join(random.sample(SOURCE, 10))
47 48
49 -def test(label, condition):
50 TEST_LOGS.append((label, condition)) 51 if condition: 52 LOG.debug("%s ... OK", label) 53 else: 54 LOG.debug("%s ... NG", label)
55 56
57 -def show_test_summary():
58 _ok = 0 59 _ng = 0 60 for label, condition in TEST_LOGS: 61 if condition: 62 _ok += 1 63 else: 64 _ng += 1 65 LOG.info("Test results: OK=%s, NG=%s" % (_ok, _ng)) 66 for label, condition in TEST_LOGS: 67 if not condition: 68 LOG.debug("NG: %s" % label)
69