File: test_spawner.py

package info (click to toggle)
python-enthoughtbase 3.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 960 kB
  • ctags: 1,034
  • sloc: python: 6,104; makefile: 9; sh: 5
file content (56 lines) | stat: -rw-r--r-- 1,783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#------------------------------------------------------------------------------
# Copyright (c) 2008, Enthought, Inc.
# All rights reserved.
# 
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license.  The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
# 
# Author: Ilan Schnell, Enthought, Inc.
#
# Description:
#     Unittest to run another (unittest) script directly.
#     In some cases this is necessary when things cannot be tested
#     with nosetests itself.
#------------------------------------------------------------------------------
import sys
import os.path
import subprocess
import unittest
import tempfile

from enthought.util.resource import store_resource, get_path


class Tests(unittest.TestCase):

    def setUp(self):
        OS_handle, fname = tempfile.mkstemp()
        os.close(OS_handle)
        self.tmpname = fname

    
    def test_refresh(self):
        """
            Run 'refresh.py' as a spawned process and test return value,
            The python source is stored into a temporary test file before
            being executed in a subprocess.
        """
        store_resource('EnthoughtBase',
                       os.path.join('enthought', 'util','tests', 'refresh.py'),
                       self.tmpname)
        
        retcode = subprocess.call([sys.executable, self.tmpname],
                                  cwd=os.path.dirname(self.tmpname))
        
        self.assertEqual(retcode, 0)


    def tearDown(self):
        os.unlink(self.tmpname)
        

if __name__ == "__main__":
    unittest.main()