~ubuntu-branches/ubuntu/wily/python-pyeclib/wily

« back to all changes in this revision

Viewing changes to test/test_core.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-11-20 02:15:48 UTC
  • Revision ID: package-import@ubuntu.com-20141120021548-j8mav6q2z1hjncei
Tags: upstream-0.9.10
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2013, Kevin Greenan (kmgreen2@gmail.com)
 
2
# All rights reserved.
 
3
#
 
4
# Redistribution and use in source and binary forms, with or without
 
5
# modification, are permitted provided that the following conditions are met:
 
6
#
 
7
# Redistributions of source code must retain the above copyright notice, this
 
8
# list of conditions and the following disclaimer.
 
9
#
 
10
# Redistributions in binary form must reproduce the above copyright notice,
 
11
# this list of conditions and the following disclaimer in the documentation
 
12
# and/or other materials provided with the distribution.  THIS SOFTWARE IS
 
13
# PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 
14
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
15
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
 
16
# NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
 
17
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
18
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
19
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
20
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
21
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
22
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
23
 
 
24
import os
 
25
import sys
 
26
import unittest
 
27
 
 
28
run_under_valgrind = False
 
29
test_cmd_prefix = ""
 
30
log_filename_prefix = ""
 
31
 
 
32
 
 
33
class TestCore(unittest.TestCase):
 
34
 
 
35
    def __init__(self, *args):
 
36
        self.pyeclib_core_test = "test_pyeclib_c.py"
 
37
        self.pyeclib_iface_test = "test_pyeclib_api.py"
 
38
 
 
39
        unittest.TestCase.__init__(self, *args)
 
40
 
 
41
    def setUp(self):
 
42
        # Determine which directory we're in
 
43
        dirs = os.getcwd().split('/')
 
44
        if dirs[-1] == 'test':
 
45
            self.pyeclib_test_dir = "."
 
46
        else:
 
47
            self.pyeclib_test_dir = "./test"
 
48
 
 
49
        # Create the array of tests to run
 
50
        self.py_test_dirs = [
 
51
            (self.pyeclib_test_dir, self.pyeclib_core_test),
 
52
            (self.pyeclib_test_dir, self.pyeclib_iface_test)
 
53
        ]
 
54
 
 
55
    def tearDown(self):
 
56
        pass
 
57
 
 
58
    def test_core(self):
 
59
        self.assertTrue(True)
 
60
        cur_dir = os.getcwd()
 
61
        print("\n")
 
62
        for (dir, test) in self.py_test_dirs:
 
63
            sys.stdout.write("Running test %s ... " % test)
 
64
            sys.stdout.flush()
 
65
            os.chdir(dir)
 
66
            if os.path.isfile(test):
 
67
                ret = os.system(
 
68
                    "%s python %s >%s/%s.%s.out 2>&1" %
 
69
                    (test_cmd_prefix, test, cur_dir,
 
70
                     log_filename_prefix, test))
 
71
 
 
72
                self.assertEqual(0, ret)
 
73
                os.system("rm -f *.pyc")
 
74
                os.chdir(cur_dir)
 
75
                print('ok')
 
76
            else:
 
77
                self.assertTrue(False)
 
78
                print('failed')
 
79
 
 
80
 
 
81
# Invoke this script as "python test_core_valgrind.py"
 
82
# for the "valgrind" variant
 
83
# (test_core_valgrind.py is a symlink to test_core.py)
 
84
if __name__ == "__main__":
 
85
    if '_valgrind' in sys.argv[0]:
 
86
        if (0 != os.system("which valgrind")):
 
87
            print("You don't appear to have 'valgrind' installed")
 
88
            sys.exit(-1)
 
89
        run_under_valgrind = True
 
90
        test_cmd_prefix = "valgrind --leak-check=full "
 
91
        log_filename_prefix = "valgrind"
 
92
    if sys.version_info<(2,7,0):
 
93
        unittest.main()
 
94
    else:
 
95
        unittest.main(verbosity=2)