def block_code(self, code, language): if language != 'python': return if re.match('^#\s*steadymark:\s*ignore', code): return item = self._tests[-1] if 'code' in item: # the same title has more than 1 code found = self.title_regex.search(item['title']) title = found.group('title').rstrip() index = int(found.group('index') or 0) if not index: index = 1 item['title'] = '{0} #{1}'.format(title, index) new_item = { 'title': '{0} #{1}'.format(title, index + 1), 'level': item['level'], 'code': code, } self._tests.append(new_item) item = self._tests[-1] else: item['code'] = text_type(code).strip() if 'title' not in item: item['title'] = 'Test #{0}'.format(len(self._tests)) self._tests.append({})
def blockcode(self, code, language): if language != 'python': return if re.match('^#\s*steadymark:\s*ignore', code): return item = self._tests[-1] if 'code' in item: # the same title has more than 1 code found = self.title_regex.search(item['title']) title = found.group('title').rstrip() index = int(found.group('index') or 0) if not index: index = 1 item['title'] = '{0} #{1}'.format(title, index) new_item = { 'title': '{0} #{1}'.format(title, index + 1), 'level': item['level'], 'code': code, } self._tests.append(new_item) item = self._tests[-1] else: item[u'code'] = text_type(code).strip() if 'title' not in item: item[u'title'] = u'Test #{0}'.format(len(self._tests)) self._tests.append({})
def header(self, title, level): t = text_type(title) t = re.sub(r'^[# ]*(.*)', '\g<1>', t) t = re.sub(r'`([^`]*)`', '\033[1;33m\g<1>\033[0m', t) self._tests.append({ 'title': t, 'level': int(level), })
def header(self, title, level): t = text_type(title) t = re.sub(r'^[# ]*(.*)', '\g<1>', t) t = re.sub(r'`([^`]*)`', '\033[1;33m\g<1>\033[0m', t) self._tests.append({ u'title': t, u'level': int(level), })
def __init__(self, filename=None, text=u''): if filename and not os.path.exists(filename): print('steadymark could not find {0}'.format(filename)) sys.exit(1) if filename: raw_md = codecs.open(filename, 'rb', 'utf-8').read() text = text_type(raw_md) self.steadymark = SteadyMark.inspect(text) self.filename = filename self.text = text
def test_find_doctest_code_with_titles(): (u"SteadyMark should find doctest and use the " "previous header as title") md = u"""# test 1 a paragraph ```python >>> raise TypeError('boom') ``` """ sm = SteadyMark.inspect(md) test1 = sm.tests[0] result, (_, failure, tb), before, after = test1.run() test1.title.should.equal("test 1") failure.should.be.a(TypeError) "boom".should.be.within(text_type(failure))
def test_find_python_code_with_titles(): (u"SteadyMark should find python code and use the " "previous header as title") md = u"""# test 1 a paragraph ```python raise ValueError('boom') ``` """ sm = SteadyMark.inspect(md) test1 = sm.tests[0] result, (_, failure, tb), before, after = test1.run() test1.title.should.equal("test 1") failure.should.be.a(ValueError) "boom".should.be.within(text_type(failure))
def format_traceback(self, test, failure): exc, exc_instance, tb = failure # formatted_tb = traceback.format_exc(exc_instance).strip() # if 'None' == formatted_tb: formatted_tb = ''.join(traceback.format_tb(tb)) formatted_tb = formatted_tb.replace( u'File "{0}"'.format(test.title), u'In the test "{0}"'.format(test.title), ) formatted_tb = formatted_tb.replace(u'@STEADYMARK@', text_type(test.title)) if SUPPORTS_ANSI: color = '\033[1;36m' else: color = '' return u'{0} {3}{1}\n{2}\n'.format( exc.__name__, exc_instance, formatted_tb, color, )
def format_traceback(self, test, failure): exc, exc_instance, tb = failure # formatted_tb = traceback.format_exc(exc_instance).strip() # if 'None' == formatted_tb: formatted_tb = ''.join(traceback.format_tb(tb)) formatted_tb = formatted_tb.replace( u'File "{0}"'.format(test.title), u'In the test "{0}"'.format(test.title), ) formatted_tb = formatted_tb.replace( u'@STEADYMARK@', text_type(test.title)) if SUPPORTS_ANSI: color = '\033[1;36m' else: color = '' return u'{0} {3}{1}\n{2}\n'.format( exc.__name__, exc_instance, formatted_tb, color, )
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. from __future__ import unicode_literals from optparse import OptionParser from steadymark.six import text_type from steadymark.version import version try: from steadymark.runner import Runner except ImportError as e: if 'misaka' in text_type(e): Runner = None else: raise def run(filenames): for filename in filenames: runner = Runner(filename) runner.run() def main(): parser = OptionParser() (options, args) = parser.parse_args() run(args or ['README.md'])
def preprocess(self, text): self._tests = [{}] return text_type(text)
def preprocess(self, text): self._tests = [{}] self.globs = globals() self.locs = locals() return text_type(text)