Exemplo n.º 1
0
def test_keeps_scope_from_test_to_test():
    (u"SteadyMark should accumulate the scope throughout the python code snippets")

    md = u"""# test 1
a paragraph

```python
value = "YAY"
```

# test 2
a paragraph

```python
assert value == 'YAY'
```
"""

    sm = SteadyMark.inspect(md)
    test1, test2 = sm.tests
    result1, failure1, before, after = test1.run()
    result2, failure2, before, after = test2.run()

    test1.title.should.equal("test 1")
    test2.title.should.equal("test 2")

    failure1.should.be.none
    failure2.should.be.none
Exemplo n.º 2
0
def test_use_same_title_for_all_tests():
    ("SteadyMark should find all the tests under the same header (title)")

    md = """# Test Foo
a paragraph

```python
assert False, 'FIRST'
```

```python
assert False, 'SECOND'
```

```python
assert False, 'THIRD'
```

    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(3)

    test1, test2, test3 = sm.tests

    test1.title.should.equal("Test Foo #1")
    eval.when.called_with(test1.code).should.throw(AssertionError, "FIRST")

    test2.title.should.equal("Test Foo #2")
    eval.when.called_with(test2.code).should.throw(AssertionError, "SECOND")

    test3.title.should.equal("Test Foo #3")
    eval.when.called_with(test3.code).should.throw(AssertionError, "THIRD")
Exemplo n.º 3
0
def test_keeps_scope_from_test_to_test():
    (u"SteadyMark should accumulate the scope throughout the python code snippets"
     )

    md = u"""# test 1
a paragraph

```python
value = "YAY"
```

# test 2
a paragraph

```python
assert value == 'YAY'
```
"""

    sm = SteadyMark.inspect(md)
    test1, test2 = sm.tests
    result1, failure1, before, after = test1.run()
    result2, failure2, before, after = test2.run()

    test1.title.should.equal("test 1")
    test2.title.should.equal("test 2")

    failure1.should.be.none
    failure2.should.be.none
Exemplo n.º 4
0
def test_use_same_title_for_all_tests():
    ("SteadyMark should find all the tests under the same header (title)")

    md = """# Test Foo
a paragraph

```python
assert False, 'FIRST'
```

```python
assert False, 'SECOND'
```

```python
assert False, 'THIRD'
```

    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(3)

    test1, test2, test3 = sm.tests

    test1.title.should.equal("Test Foo #1")
    eval.when.called_with(test1.code).should.throw(AssertionError, "FIRST")

    test2.title.should.equal("Test Foo #2")
    eval.when.called_with(test2.code).should.throw(AssertionError, "SECOND")

    test3.title.should.equal("Test Foo #3")
    eval.when.called_with(test3.code).should.throw(AssertionError, "THIRD")
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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 = unicode(raw_md)

        self.steadymark = SteadyMark.inspect(text)
        self.filename = filename
        self.text = text
Exemplo n.º 7
0
    def __init__(self, filename=None, text=""):
        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 = str(raw_md)

        self.steadymark = SteadyMark.inspect(text)
        self.filename = filename
        self.text = text
Exemplo n.º 8
0
def test_find_inline_doctests_with_titles():
    ("SteadyMark should find docstrings and use the "
     "previous header as title")

    md = """# test 1
a paragraph

```python
>>> x = 'doc'
>>> y = 'test'
>>> assert (x + y) == 'doctest'
```

# not a test

foobar

```ruby
ruby no!
```

# another part

## test 2

a paragraph

```python
assert False, 'uh yeah'
```
    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(2)

    test1, test2 = sm.tests

    test1.title.should.equal("test 1")
    test1.raw_code.should.equal(">>> x = 'doc'\n"
                                ">>> y = 'test'\n"
                                ">>> assert (x + y) == 'doctest'")

    this(test1.code).should.be.a('doctest.DocTest')
    test1.run()
    test2.title.should.equal("test 2")
    test2.raw_code.should.equal("assert False, 'uh yeah'")
    eval.when.called_with(test2.code).should.throw(AssertionError, "uh yeah")
Exemplo n.º 9
0
def test_find_inline_doctests_with_titles():
    (u"SteadyMark should find docstrings and use the "
     "previous header as title")

    md = u"""# test 1
a paragraph

```python
>>> x = 'doc'
>>> y = 'test'
>>> assert (x + y) == 'doctest'
```

# not a test

foobar

```ruby
ruby no!
```

# another part

## test 2

a paragraph

```python
assert False, 'uh yeah'
```
    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(2)

    test1, test2 = sm.tests

    test1.title.should.equal("test 1")
    test1.raw_code.should.equal(">>> x = 'doc'\n"
                                ">>> y = 'test'\n"
                                ">>> assert (x + y) == 'doctest'")

    this(test1.code).should.be.a('doctest.DocTest')
    test1.run()
    test2.title.should.equal("test 2")
    test2.raw_code.should.equal("assert False, 'uh yeah'")
    eval.when.called_with(test2.code).should.throw(AssertionError, "uh yeah")
Exemplo n.º 10
0
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))
Exemplo n.º 11
0
def test_skip_tests_marked_with_ignore():
    ("SteadyMark should skip tests with the 'ignore' modeline")

    md = """# My test
```python
# steadymark: ignore
This should break, but it won't because steady mark will ignore this
```

# Another test
```python
>>> 1 + 1
2
```
"""
    sm = SteadyMark.inspect(md)
    sm.tests.should.have.length_of(1)
    sm.tests[0].title.should.be.equal("Another test")
Exemplo n.º 12
0
def test_skip_tests_marked_with_ignore():
    ("SteadyMark should skip tests with the 'ignore' modeline")

    md = """# My test
```python
# steadymark: ignore
This should break, but it won't because steady mark will ignore this
```

# Another test
```python
>>> 1 + 1
2
```
"""
    sm = SteadyMark.inspect(md)
    sm.tests.should.have.length_of(1)
    sm.tests[0].title.should.be.equal("Another test")
Exemplo n.º 13
0
def test_find_doctest_code_with_titles():
    ("SteadyMark should find doctest and use the "
     "previous header as title")

    md = """# 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))
Exemplo n.º 14
0
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(unicode(failure))
Exemplo n.º 15
0
def test_find_python_code_with_titles():
    ("SteadyMark should find python code and use the "
     "previous header as title")

    md = """# test 1
a paragraph

```python
assert False, 'boom!'
```

# not a test

foobar

```ruby
ruby no!
```

# another part

## test 2

a paragraph

```python
assert False, 'uh yeah'
```
    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(2)

    test1, test2 = sm.tests

    test1.title.should.equal("test 1")
    test1.raw_code.should.equal("assert False, 'boom!'")
    eval.when.called_with(test1.code).should.throw(AssertionError, "boom!")

    test2.title.should.equal("test 2")
    test2.raw_code.should.equal("assert False, 'uh yeah'")
    eval.when.called_with(test2.code).should.throw(AssertionError, "uh yeah")
Exemplo n.º 16
0
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
assert False, 'boom!'
```

# not a test

foobar

```ruby
ruby no!
```

# another part

## test 2

a paragraph

```python
assert False, 'uh yeah'
```
    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(2)

    test1, test2 = sm.tests

    test1.title.should.equal("test 1")
    test1.raw_code.should.equal("assert False, 'boom!'")
    eval.when.called_with(test1.code).should.throw(AssertionError, "boom!")

    test2.title.should.equal("test 2")
    test2.raw_code.should.equal("assert False, 'uh yeah'")
    eval.when.called_with(test2.code).should.throw(AssertionError, "uh yeah")
Exemplo n.º 17
0
def test_find_python_code_with_titles():
    ("SteadyMark should find python code and use the "
     "previous header as title")

    md = """# 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(str(failure))