type migration tests fixed
[idea/community.git] / python / helpers / pycharm / tcmessages.py
1 import sys
2
3
4 class TeamcityServiceMessages:
5     quote = {"'": "|'", "|": "||", "\n": "|n", "\r": "|r", ']': '|]'}
6
7     def __init__(self, output=sys.stdout, prepend_linebreak=False):
8         self.output = output
9         self.prepend_linebreak = prepend_linebreak
10
11     def escapeValue(self, value):
12         if sys.version_info[0] <= 2 and isinstance(value, unicode):
13             s = value.encode("utf-8")
14         else:
15             s = str(value)
16         return "".join([self.quote.get(x, x) for x in s])
17
18     def message(self, messageName, **properties):
19         s = "##teamcity[" + messageName
20         for k, v in properties.items():
21             if v is None:
22                 continue
23             s = s + " %s='%s'" % (k, self.escapeValue(v))
24         s += "]\n"
25
26         if self.prepend_linebreak: self.output.write("\n")
27         self.output.write(s)
28
29     def testSuiteStarted(self, suiteName, location=None):
30         self.message('testSuiteStarted', name=suiteName, locationHint=location)
31
32     def testSuiteFinished(self, suiteName):
33         self.message('testSuiteFinished', name=suiteName)
34
35     def testStarted(self, testName, location=None):
36         self.message('testStarted', name=testName, locationHint=location)
37
38     def testFinished(self, testName, duration=None):
39         self.message('testFinished', name=testName, duration=duration)
40
41     def testIgnored(self, testName, message=''):
42         self.message('testIgnored', name=testName, message=message)
43         self.testFinished(testName)
44
45
46     def testFailed(self, testName, message='', details='', expected='', actual='', duration=None):
47         """
48         Marks test as failed. *CAUTION*: This method calls ``testFinished``, so you do not need
49         to call it second time. Try to provide ``duration`` if possible.
50
51         """
52         if expected and actual:
53             self.message('testFailed', type='comparisonFailure', name=testName, message=message,
54                          details=details, expected=expected, actual=actual)
55         else:
56             self.message('testFailed', name=testName, message=message, details=details)
57         self.testFinished(testName, int(duration) if duration else None)
58
59     def testError(self, testName, message='', details='', duration=None):
60         self.message('testFailed', name=testName, message=message, details=details, error="true")
61         self.testFinished(testName, int(duration) if duration else None)
62
63     def testStdOut(self, testName, out):
64         self.message('testStdOut', name=testName, out=out)
65
66     def testStdErr(self, testName, out):
67         self.message('testStdErr', name=testName, out=out)
68
69     def testCount(self, count):
70         self.message('testCount', count=count)
71
72     def testMatrixEntered(self):
73         self.message('enteredTheMatrix')