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)
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
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)
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
def testDownloadWithoutContentDisposition(self): t = path(TempIO(True)) d = Downloader(t, 'http://filehost.yourcorp.com/txpeng540.exe') d.Acquire() assert t / 'txpeng540.exe' in t.files() d.Release() assert not t.exists()
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
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): 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
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
def testDownloadWithContentDispositionFileName(self): t = path(TempIO(True)) d = Downloader(t, 'https://ninite.com/api/installer?app=Chrome&key=vmware') downloadPath = t / 'Ninite Chrome Installer.exe' res = d.Acquire() # Ensure that Acquire returns the path to the downloaded file. # Perhaps put this in its own test. assert res == downloadPath assert downloadPath in t.files() d.Release() assert not t.exists()
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)
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
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)
import sys import os from nose.exc import SkipTest from nose.tools import eq_ import unittest from fixture import DataSet, TempIO, GoogleDatastoreFixture from fixture.util import reset_log_level from fixture.test import conf, attr tmp = TempIO() def setup(): # for prying eyes: NoseGAE http://code.google.com/p/nose-gae/ does this better groot = "/usr/local/google_appengine" if os.path.exists(groot): sys.path.append(groot) sys.path.append(os.path.join(groot, "lib/django")) sys.path.append(os.path.join(groot, "lib/webob")) sys.path.append(os.path.join(groot, "lib/yaml/lib")) sys.path.insert(0, os.path.join(groot, "lib/antlr3")) import google.appengine import webob import yaml import django import antlr3 from google.appengine.tools import dev_appserver appid = "<fixture>" dev_appserver.SetupStubs(appid,
def reset_heavy_dsn(): global HEAVY_DSN if HEAVY_DSN_IS_TEMPIO: tmp = TempIO(deferred=True) HEAVY_DSN = 'sqlite:///%s' % tmp.join("tmp.db")
def setUp(self): self.tmp = TempIO()
def test_del_self_destructs(): """asserts that a module level reference self destructs without exception.""" global _TMP _TMP = TempIO()
def makeSuite(self): self.tmp = TempIO() self.tmp.putfile("test_to_pass.py", """def test_good(): pass""") return self.tmp