File: thread_printer.py

package info (click to toggle)
indigo 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 48,936 kB
  • sloc: ansic: 332,816; cpp: 169,470; python: 20,033; java: 13,701; cs: 9,979; asm: 8,475; sql: 6,743; xml: 6,354; javascript: 1,245; sh: 555; php: 506; makefile: 54
file content (36 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download
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
from __future__ import with_statement
import sys
if sys.version_info < (3, 0):
	from cStringIO import StringIO
else:
	from io import StringIO

import inspect
import os

class ThreadPrinter(object): 
    def __init__(self, lock): 
        self.fhs = {}
        self.lock = lock
        
    def write(self, value): 
        with self.lock:
            frm = inspect.stack()[1][1]
            splittedFromPath = frm.split(os.path.sep)            
            test_group = splittedFromPath[-2]
            test = splittedFromPath[-1]
            curTestName = '%s/%s' % (test_group, test)
            if curTestName in self.fhs:
                f = self.fhs[curTestName]            
            else:
                f = StringIO()
            f.write(value)
            self.fhs[curTestName] = f
        
    def getValueByTestName(self, testName):
        result = ''
        for key, value in self.fhs.items():
            key = key.replace('_modified', '')
            if key == testName:
                result = value.getvalue()
        return result