Ejemplo n.º 1
0
    def makeSuite(self):
        tmp = TempIO()
        tmp.putfile('test_lone_error.py', """
def test_lone_error():
    raise AssertionError
""")
        return tmp
Ejemplo n.º 2
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail.py", """\
def test_bad():
    print "it's no good!!!"
    assert False""")
        return self.tmp
Ejemplo n.º 3
0
class TestSuccessfulRun(WithTestMethod, NoseTTYTester):
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_pass.py", """def test_good(): pass""")
        return self.tmp

    def test_absence_of_error_does_nothing(self):
        assert "test_to_pass.py" not in self.nose
Ejemplo n.º 4
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail_testclass.py", """\
class TestToFail(object):
    def test_bad_from_testclass(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 5
0
class TestSuccessfulRun(WithTestMethod, NoseTTYTester):
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_pass.py",
            """def test_good(): pass""")
        return self.tmp
        
    def test_absence_of_error_does_nothing(self):
        assert "test_to_pass.py" not in self.nose
Ejemplo n.º 6
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail_unittest.py", """\
import unittest
class TestToFail(unittest.TestCase):
    def test_bad_from_unittest(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 7
0
def exec_if_supported(code, globals={}, locals={}):
    # seems that for using from __future__ exec needs to think it's compiling a 
    # module
    tmp = TempIO()
    try:
        try:
            mod = compile(code, tmp.join("code.py"), 'exec')
        except SyntaxError:
            raise SkipTest
        else:
            eval(mod, globals, locals)
    finally:
        del tmp
Ejemplo n.º 8
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail_nested.py", """\
def two():
    raise ValueError
def three():
    two()
def four():
    three()
def test_nested_fail():
    four()""")
        return self.tmp
Ejemplo n.º 9
0
class EditErrorsByNumber(EditingErrorsByNumber):
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail_nested.py",
            """\
def two():
    raise ValueError
def three():
    two()
def four():
    three()
def test_nested_fail():
    four()""")
        return self.tmp
Ejemplo n.º 10
0
class WithTestMethod(object):
    """mixin to run tests with a failing method"""
    def assert_failure_edited(self):
        self.inputLines("1")
        assert "+3" in self.nose
        assert "test_to_fail.py" in self.nose

    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail.py", """\
def test_bad():
    print "it's no good!!!"
    assert False""")
        return self.tmp
Ejemplo n.º 11
0
class WithTestMethod(object):
    """mixin to run tests with a failing method"""
    def assert_failure_edited(self):
        self.inputLines("1")
        assert "+3" in self.nose
        assert "test_to_fail.py" in self.nose
        
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail.py",
            """\
def test_bad():
    print "it's no good!!!"
    assert False""")
        return self.tmp
Ejemplo n.º 12
0
def test_putfile():
    tmp = TempIO()
    cwd = os.getcwd()
    try:

        fname = join(tmp, 'french.txt')
        putfile(fname, french)

        assert exists(fname)

        f = open(fname, 'r')
        contents = f.read()
        f.close()
        assert contents == french

        # can make lazy dirs ..
        fname = join(tmp, 'ou/est/tu/frenchy.txt')
        putfile(fname, "")
        assert exists(fname)

        # relative :
        os.chdir(tmp)
        putfile('bahh', '')
        assert exists(join(tmp, 'bahh'))

    finally:
        del tmp
        os.chdir(cwd)
Ejemplo n.º 13
0
class WithTestClass(object):
    """mixin to run tests with a failing test class"""
    def assert_failure_edited(self):
        self.inputLines("1")
        assert "+3" in self.nose
        assert "test_to_fail_testclass.py" in self.nose
        
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail_testclass.py",
            """\
class TestToFail(object):
    def test_bad_from_testclass(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 14
0
 def test_keywords(self):
     self.tmp_custom = TempIO(prefix='foobar_', dir=self.tmp)
     try:
         assert exists(join(self.tmp, basename(self.tmp_custom)))
         assert basename(self.tmp_custom).startswith('foobar_')
     finally:
         del self.tmp_custom
Ejemplo n.º 15
0
class WithTestClass(object):
    """mixin to run tests with a failing test class"""
    def assert_failure_edited(self):
        self.inputLines("1")
        assert "+3" in self.nose
        assert "test_to_fail_testclass.py" in self.nose

    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail_testclass.py", """\
class TestToFail(object):
    def test_bad_from_testclass(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 16
0
class WithUnitTest(object):
    """mixin to run tests with a failing unittest.TestCase"""
    def assert_failure_edited(self):
        self.inputLines("1")
        assert "+4" in self.nose
        assert "test_to_fail_unittest.py" in self.nose
        
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail_unittest.py",
            """\
import unittest
class TestToFail(unittest.TestCase):
    def test_bad_from_unittest(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 17
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail.py",
            """\
def test_bad():
    print "it's no good!!!"
    assert False""")
        return self.tmp
Ejemplo n.º 18
0
class WithUnitTest(object):
    """mixin to run tests with a failing unittest.TestCase"""
    def assert_failure_edited(self):
        self.inputLines("1")
        assert "+4" in self.nose
        assert "test_to_fail_unittest.py" in self.nose

    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile(
            "test_to_fail_unittest.py", """\
import unittest
class TestToFail(unittest.TestCase):
    def test_bad_from_unittest(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 19
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail_testclass.py",
            """\
class TestToFail(object):
    def test_bad_from_testclass(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 20
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.putfile("test_to_fail_unittest.py",
            """\
import unittest
class TestToFail(unittest.TestCase):
    def test_bad_from_unittest(self):
        assert False
            """)
        return self.tmp
Ejemplo n.º 21
0
def test_session_maintains_state():
    tmp = TempIO()
    data_file = tmp.join(".session")
    session = Session(data_file, "foo")
    eq_(session.started_as_parent(), True)
    # now it's set...
    eq_(session.started_as_parent(), False)
    eq_(session.started_as_parent(), False)
    
    session2 = Session(data_file, "foo2")
    eq_(session2.started_as_parent(), True)
    eq_(session2.started_as_parent(), False)
    
    session.unregister_parent()
    eq_(session.started_as_parent(), True)
    eq_(session2.started_as_parent(), False)
    
    session2.unregister_parent()
    eq_(session2.started_as_parent(), True)
Ejemplo n.º 22
0
def test_session_maintains_state():
    tmp = TempIO()
    data_file = tmp.join(".session")
    session = Session(data_file, "foo")
    eq_(session.started_as_parent(), True)
    # now it's set...
    eq_(session.started_as_parent(), False)
    eq_(session.started_as_parent(), False)

    session2 = Session(data_file, "foo2")
    eq_(session2.started_as_parent(), True)
    eq_(session2.started_as_parent(), False)

    session.unregister_parent()
    eq_(session.started_as_parent(), True)
    eq_(session2.started_as_parent(), False)

    session2.unregister_parent()
    eq_(session2.started_as_parent(), True)
Ejemplo n.º 23
0
    def makeSuite(self):
        tmp = TempIO()
        tmp.putfile('test_many_errors.py', """
def test_assert_one():
    raise AssertionError("nope x is not y")
def test_one():
    pass
def test_assert_two():
    raise AssertionError("sory y is definitely not x")
def test_two():
    pass
def test_value_one():
    raise ValueError
def test_value_two():
    raise ValueError
def test_good_one():
    pass
def test_good_two():
    pass
""")
        return tmp
Ejemplo n.º 24
0
def test_mkdirall():
    tmp = TempIO()
    cwd = os.getcwd()
    try:
        mkdirall(join(tmp, 'blah/blah/'))
        assert exists(join(tmp, 'blah/blah'))

        # relative too ...
        os.chdir(tmp)
        mkdirall('ici/ou/la')
        assert exists('ici')
        assert exists('ici/ou')
        assert exists('ici/ou/la')

    finally:
        del tmp
        os.chdir(cwd)
Ejemplo n.º 25
0
    def makeSuite(self):
        self.tmp = TempIO()
        self.tmp.test = "test"
        self.tmp.test.putfile(
            "__init__.py", """
import os
def teardown():
    f = open(os.path.join(os.path.dirname(__file__),'foo.out'), 'w')
    f.write("blah")
    f.close()
    pass
            """)
        self.tmp.test.putfile(
            "test_foo.py", """
def test_will_fail():
    raise AssertionError
            """)
        return self.tmp
Ejemplo n.º 26
0
 def setUp(self):
     self.tmp = TempIO()
Ejemplo n.º 27
0
class TestTempIO(object):
    def setUp(self):
        self.tmp = TempIO()
    
    def tearDown(self):
        if hasattr(self, 'tmp'):
            del self.tmp
    
    @attr(unit=True)
    def test_deferred(self):
        tmp = TempIO(deferred=True)
        root = str(tmp)
        assert exists(root)
        del tmp
        assert exists(root)
    
        tmp2 = TempIO(deferred=False)
        root = str(tmp2)
        assert exists(root)
        del tmp2
        assert not exists(root)

    @attr(unit=True)
    def test_del(self):
        root = copy(self.tmp)
        del self.tmp
        assert not exists(root)

    @attr(unit=True)
    def test_keywords(self):
        self.tmp_custom = TempIO(prefix='foobar_', dir=self.tmp)
        try:
            assert exists(join(self.tmp, basename(self.tmp_custom)))
            assert basename(self.tmp_custom).startswith('foobar_')
        finally:
            del self.tmp_custom

    @attr(unit=True)
    def test_mkdir(self):
        base1 = self.tmp.mkdir('base1')
        assert exists(join(self.tmp, base1))
        base2 = self.tmp.mkdir('base2')
        assert exists(join(self.tmp, base2))

    @attr(unit=True)
    def test_newdir(self):
        self.tmp.rick_james = "rick_james"
        assert exists(self.tmp.rick_james)
        assert self.tmp.rick_james.startswith(self.tmp)
        assert self.tmp.rick_james.endswith("rick_james")
        
        self.tmp.rick_james = "rick james"
        assert exists(self.tmp.rick_james)
        assert self.tmp.rick_james.startswith(self.tmp)
        assert self.tmp.rick_james.endswith("rick james")
        
        self.tmp.rick_james = "rick_james/i/love/you"
        assert exists(self.tmp.rick_james)
        assert self.tmp.rick_james.startswith(self.tmp)
        assert self.tmp.rick_james.endswith("rick_james/i/love/you")
    
    @attr(unit=True)
    def test_path_interface(self):
        self.tmp.dupes = "processed/dupes"
        def endswith(p, end):
            assert p.endswith(end), "%s did not end in %s" % (p,end)
        
        eq_(self.tmp.dupes, path.join(self.tmp, "processed/dupes"))
        eq_(self.tmp.dupes.abspath(), 
                path.abspath(path.join(self.tmp, "processed/dupes")))
        eq_(self.tmp.dupes.basename(), "dupes")
        eq_(self.tmp.dupes.dirname(), path.join(self.tmp, "processed"))
        eq_(self.tmp.dupes.normpath(), path.normpath(self.tmp.dupes))
        eq_(self.tmp.dupes.exists(), True)
        eq_(self.tmp.dupes.join("foo", "bar"), path.abspath(path.join(
                                    self.tmp, "processed/dupes/foo/bar")))
        eq_(self.tmp.dupes.join("foo", "bar").exists(), False)
        
        self.tmp.dupes.more = "foo/bar"
        eq_(path.exists(path.join(self.tmp.dupes, "foo", "bar")), True)
        eq_(self.tmp.dupes.join("foo", "bar").exists(), True)
        
        eq_(self.tmp.dupes.realpath(), 
                path.realpath(path.join(self.tmp, "processed/dupes")))
        eq_(self.tmp.dupes.splitpath(), path.split(self.tmp.dupes))
        eq_(self.tmp.dupes.splitext(), (path.realpath(path.join(self.tmp, 
                                                    "processed/dupes")), ""))

    @attr(unit=True)
    def test_putfile(self):
        self.tmp.putfile('frenchy.txt', french)

        assert exists(join(self.tmp, 'frenchy.txt'))
        assert open(join(self.tmp, 'frenchy.txt'), 'r').read() == french

        abspath = self.tmp.putfile('petite/grenouille/frenchy.txt', french)
        exppath = join(self.tmp, 'petite/grenouille/frenchy.txt')
        assert exists(exppath)
        eq_(abspath, exppath)

        # check laziness of putfile's mkdir'ing :
        self.tmp.putfile('petite/grenouille/ribbit/frenchy.txt', french)
        assert exists(join(self.tmp, 
                            'petite/grenouille/ribbit/frenchy.txt'))
        # make sure that a second call will only create directories necessary:
        self.tmp.putfile('petite/grenouille/ribbit/foo.txt', "foo")
        
    @attr(unit=True)
    def test_putfile_mode(self):
        self.tmp.putfile('frenchy.txt', b"", 'wb')
        f = open(join(self.tmp, 'frenchy.txt'), 'rb')
        f.read()
    
    @attr(unit=True)
    @raises(TypeError)
    def test_putfile_accepts_only_relative_paths(self):
        self.tmp.putfile('/petite/grenouille/ribbit/frenchy.txt', "franch")

    @attr(unit=True)
    def test_rmtree(self):
        root = str(self.tmp)
        self.tmp.rmtree()
        assert not exists(root)

    @attr(unit=True)
    def test_root(self):
        assert isdir(self.tmp)
Ejemplo n.º 28
0
 def makeSuite(self):
     self.tmp = TempIO()
     self.tmp.putfile("test_to_pass.py", """def test_good(): pass""")
     return self.tmp
Ejemplo n.º 29
0
 def makeSuite(self):
     self.tmp = TempIO()
     self.tmp.putfile("test_to_pass.py",
         """def test_good(): pass""")
     return self.tmp
Ejemplo n.º 30
0
Archivo: conf.py Proyecto: JamesX88/tes
def reset_heavy_dsn():
    global HEAVY_DSN
    if HEAVY_DSN_IS_TEMPIO:        
        tmp = TempIO(deferred=True)
        HEAVY_DSN = 'sqlite:///%s' % tmp.join("tmp.db")