def test_writes_package(self): resource = StubPackageResource('foo', [('bar.py', 'woo')]) pkg = resource.getResource() self.addCleanup(resource.finishedWith, pkg) self.assertEqual('', open(os.path.join(pkg.base, 'foo', '__init__.py')).read()) self.assertEqual('woo', open(os.path.join(pkg.base, 'foo', 'bar.py')).read())
def test_writes_package(self): resource = StubPackageResource('foo', [('bar.py', 'woo')]) pkg = resource.getResource() self.addCleanup(resource.finishedWith, pkg) self.assertEqual( '', open(os.path.join(pkg.base, 'foo', '__init__.py')).read()) self.assertEqual('woo', open(os.path.join(pkg.base, 'foo', 'bar.py')).read())
class StubbedTestrResource(TestResource): resources = [("stubpackage", StubPackageResource('testrepository', [('commands.py', r"""import sys def run_argv(argv, stdin, stdout, stderr): sys.stdout.write("%s %s %s\n" % (sys.stdin is stdin, sys.stdout is stdout, sys.stderr is stderr)) sys.stdout.write("%s\n" % argv) return len(argv) - 1 """)]))] def make(self, dependency_resources): stub = dependency_resources['stubpackage'] path = os.path.join(os.path.dirname(__file__), '..', '..', 'testr') # Make a copy of the testr script as running in place uses the current # library, not the stub library. execpath = os.path.join(stub.base, 'testr') source = open(path, 'rb') try: testr_contents = source.read() finally: source.close() target = open(execpath, 'wb') try: target.write(testr_contents) finally: target.close() return StubbedTestr(execpath)
def __init__(self, cmd_name): TestResource.__init__(self) cmd_name = cmd_name.replace('-', '_') self.resources.append( ('pkg', StubPackageResource( 'commands', [('%s.py' % cmd_name, """from testrepository.commands import Command class %s(Command): def run(self): pass """ % cmd_name)], init=False))) self.cmd_name = cmd_name
def test_no__init__(self): resource = StubPackageResource('foo', [('bar.py', 'woo')], init=False) pkg = resource.getResource() self.addCleanup(resource.finishedWith, pkg) self.assertFalse( os.path.exists(os.path.join(pkg.base, 'foo', '__init__.py')))
def test_has_tempdir(self): resource = StubPackageResource('foo', []) self.assertEqual(1, len(resource.resources)) self.assertIsInstance(resource.resources[0][1], TempDirResource)
def test_no__init__(self): resource = StubPackageResource('foo', [('bar.py', 'woo')], init=False) pkg = resource.getResource() self.addCleanup(resource.finishedWith, pkg) self.assertFalse(os.path.exists(os.path.join(pkg.base, 'foo', '__init__.py')))