def print_(self, printHashes=False, margin='', result=None): """ Print information about the database. @param printHashes: If C{True}, print all hashes and associated subjects. @param margin: A C{str} that should be inserted at the start of each line of output. @param result: A C{MultilineString} instance, or C{None} if a new C{MultilineString} should be created. @return: If C{result} was C{None}, return a C{str} representation of the database, else C{None}. """ if result is None: result = MultilineString(margin=margin) returnNone = False else: returnNone = True coro = self._component.call('print_', printHashes=printHashes, margin=margin) loop = asyncio.get_event_loop() result.append(loop.run_until_complete(coro), verbatim=True) if not returnNone: return str(result)
def print_(self, printHashes=False, margin='', result=None): """ Print information about this connector. @param printHashes: If C{True}, print all hashes and associated subjects from the backend. @param margin: A C{str} that should be inserted at the start of each line of output. @param result: A C{MultilineString} instance, or C{None} if a new C{MultilineString} should be created. @return: If C{result} was C{None}, return a C{str} representation of the connector, else C{None}. """ if result is None: result = MultilineString(margin=margin) returnNone = False else: returnNone = True if printHashes: result.append('Backends:') result.indent() self._backend.print_(margin=margin, result=result) result.outdent() if not returnNone: return str(result)
def testOneLineTrue(self): """ If a multiline string has one thing appended to it, it must be considered True in a Boolean test. """ s = MultilineString() s.append('test') self.assertTrue(s)
def testAppendOneLine(self): """ If a multiline string has one thing appended to it, its str representation must be just that string. """ s = MultilineString() s.append('test') self.assertEqual('test', str(s))
def testOneLineLineCount(self): """ If a multiline string has one thing appended to it, its line count must be one. """ s = MultilineString() s.append('test') self.assertEqual(1, s.lineCount())
def testOneLineLength(self): """ If a multiline string has one thing appended to it, its length must be the length of that string. """ s = MultilineString() s.append('test') self.assertEqual(4, len(s))
def testAppendTwoLines(self): """ If a multiline string has two things appended to it, its str representation must have the two strings, separated by a newline. """ s = MultilineString() s.append('test1') s.append('test2') self.assertEqual('test1\ntest2', str(s))
def testTwoLinesLineCount(self): """ If a multiline string has two things appended to it, its line count must be 2. """ s = MultilineString() s.append('test1') s.append('test2') self.assertEqual(2, s.lineCount())
def testTwoLinesLength(self): """ If a multiline string has two things appended to it, its length must be the sum of the two lengths plus one for the newline separator. """ s = MultilineString() s.append('123') s.append('45678') self.assertEqual(9, len(s))
def testAppendTwoLinesWithMargin(self): """ If a multiline string with a left margin has two things appended to it, its str representation must have the two strings, separated by a newline and each line must start with the margin. """ s = MultilineString(margin='+ ') s.append('test1') s.append('test2') self.assertEqual('+ test1\n+ test2', str(s))
def testNonDefaultIndent(self): """ If a multiline string has two things appended to it, and the second is indented, its str representation must have the two strings, separated by a newline, and the second string must be indented using the indent value passed to __init__. """ s = MultilineString(indent='\t') s.append('test1') s.indent() s.append('test2') self.assertEqual('test1\n\ttest2', str(s))
def testDefaultIndent(self): """ If a multiline string has two things appended to it, and the second is indented, its str representation must have the two strings, separated by a newline, and the second string must be indented by two spaces (the default). """ s = MultilineString() s.append('test1') s.indent() s.append('test2') self.assertEqual('test1\n test2', str(s))
def __str__(self): """ Summarize the variable's statistics. @return: A C{str} summary of the variable's statistics. """ summary = self.summary() result = MultilineString() result.append('%s:' % self._description) result.indent() result.extend([ 'Count: %d' % summary['count'], 'Max: %s' % summary['max'], 'Mean: %.4f' % summary['mean'], 'Median: %.4f' % summary['median'], 'Min: %s' % summary['min'], 'SD: %.4f' % summary['sd'], 'Variance: %.4f' % summary['variance'], ]) return str(result)
def print_(self, margin='', result=None): """ Print find parameter values. @param margin: A C{str} that should be inserted at the start of each line of output. @param result: A C{MultilineString} instance, or C{None} if a new C{MultilineString} should be created. @return: If C{result} was C{None}, return a C{str} representation of the parameters, else C{None}. """ if result is None: result = MultilineString(margin=margin) returnNone = False else: returnNone = True result.append('Find parameters:') result.indent() result.extend([ 'Significance method: %s' % self.significanceMethod, 'Significance fraction: %f' % self.significanceFraction, 'Bin Score Method: %s' % self.binScoreMethod, 'Feature match score: %f' % self.featureMatchScore, 'Feature mismatch score: %f' % self.featureMismatchScore, 'Overall Score Method: %s' % self.overallScoreMethod, 'Delta scale: %f' % self.deltaScale, 'Weights: ' ]) result.indent() for key in sorted(self.weights): result.append('%s: %f' % (key, self.weights[key])) result.outdent() result.outdent() if not returnNone: return str(result)
def testAppendVerbatim(self): """ If a multiline string is given a verbatim string to append, its representation must be as expected. """ s = MultilineString() s.indent() s.append('test1') s.append(' test2\n test3', verbatim=True) s.append('test4') self.assertEqual(' test1\n test2\n test3\n test4', str(s))
def testAppendVerbatimLineCount(self): """ If a multiline string is given a verbatim string to append, its line count must be correct. """ s = MultilineString() s.indent() s.append('test1') s.append(' test2\n test3', verbatim=True) s.append('test4') self.assertEqual(4, s.lineCount())
def testIndentOutdent(self): """ If a multiline string has three things appended to it, and only the second is indented, its str representation must have the three strings, separated by newlines, and the second string must be indented. """ s = MultilineString() s.append('test1') s.indent() s.append('test2') s.outdent() s.append('test3') self.assertEqual('test1\n test2\ntest3', str(s))
def testIndentOutdentWithMargin(self): """ If a multiline string with a margin has three things appended to it, and only the second is indented, its str representation must have the three strings, separated by newlines, the second string must be indented, and each line must be preceeded by the margin. """ s = MultilineString(indent='\t', margin='>>> ') s.append('test1') s.indent() s.append('test2') s.outdent() s.append('test3') self.assertEqual('>>> test1\n>>> \ttest2\n>>> test3', str(s))
def compare(self, other): """ Compare our parameters against another C{DatabaseParameters} instance. @param other: A C{DatabaseParameters} instance. @return: A C{str} summary of the parameter differences if any, else C{None}. """ err = MultilineString() err.append('Summary of differences:') err.indent() ourLandmarks = self.landmarkFinderNames() otherLandmarks = other.landmarkFinderNames() if ourLandmarks != otherLandmarks: err.append("Param 'landmarks' values %r and %r differ." % (ourLandmarks, otherLandmarks)) ourTrigPoints = self.trigPointFinderNames() otherTrigPoints = other.trigPointFinderNames() if ourTrigPoints != otherTrigPoints: err.append("Param 'trigPoints' values %r and %r differ." % (ourTrigPoints, otherTrigPoints)) for param in ('limitPerLandmark', 'maxDistance', 'minDistance', 'distanceBase', 'featureLengthBase', 'randomLandmarkDensity', 'randomTrigPointDensity', 'acAlphaHelixFilename', 'acAlphaHelix310Filename', 'acAlphaHelixCombinedFilename', 'acAlphaHelixPiFilename', 'acExtendedStrandFilename'): ours = getattr(self, param) others = getattr(other, param) if ours != others: err.append('Param %r values %r and %r differ.' % (param, ours, others)) # We have an error if the multi-line string result has more than # the initial 'Summary of differences' heading line. return str(err) if err.lineCount() > 1 else None
def testAppendReturnsSelf(self): """ The append method must return the MultilineString instance. """ s = MultilineString() self.assertIs(s, s.append('test'))