Example #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
Example #2
0
def test_use_same_title_for_all_tests():
    (u"SteadyMark should find all the tests under the same header (title)")

    md = u"""# Test Foo
a paragraph

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

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

    sm = SteadyMark.inspect(md)

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

    test1, test2 = 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")
Example #3
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")
Example #4
0
def test_skip_tests_marked_with_ignore():
    (u"SteadyMark should skip tests with the 'ignore' modeline")

    md = u"""# 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')
Example #5
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))
Example #6
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")