def makeSuite(self): tmp = TempIO() tmp.putfile('test_lone_error.py', """ def test_lone_error(): raise AssertionError """) return tmp
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
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
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
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
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
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
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
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
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
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
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)
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)