def testExistingFile(self):
     '''Test SimpleFile class with existing file.'''
     f = SimpleFile(self.existing_filename)
     self.assertEqual(f.filename(), self.existing_filename)
     f.open()
     self.assertNotEqual(f.size(), 0)
     f.close()
示例#2
0
 def testExistingFile(self):
     '''Test SimpleFile class with existing file.'''
     f = SimpleFile(self.existing_filename)
     self.assertEqual(f.filename(), self.existing_filename)
     f.open()
     self.assertNotEqual(f.size(), 0)
     f.close()
示例#3
0
    def testMonkeyPatchOnMethodWithStaticAndNonStaticOverloads(self):
        '''Injects new 'exists' on a SimpleFile instance and makes C++ call it.'''
        simplefile = SimpleFile('foobar')

        # Static 'exists'
        simplefile.exists('sbrubbles')
        self.assertFalse(self.duck_method_called)
        # Non-static 'exists'
        simplefile.exists()
        self.assertFalse(self.duck_method_called)

        def myExists(obj):
            self.duck_method_called = True
            return False
        simplefile.exists = MethodTypeCompat(myExists, simplefile)

        # Static 'exists' was overridden by the monkey patch, which accepts 0 arguments
        self.assertRaises(TypeError, simplefile.exists, 'sbrubbles')
        # Monkey patched exists
        simplefile.exists()
        self.assertTrue(self.duck_method_called)

        simplefile.exists = None
示例#4
0
    def testMonkeyPatchOnMethodWithStaticAndNonStaticOverloads(self):
        '''Injects new 'exists' on a SimpleFile instance and makes C++ call it.'''
        simplefile = SimpleFile('foobar')

        # Static 'exists'
        simplefile.exists('sbrubbles')
        self.assertFalse(self.duck_method_called)
        # Non-static 'exists'
        simplefile.exists()
        self.assertFalse(self.duck_method_called)

        def myExists(obj):
            self.duck_method_called = True
            return False
        simplefile.exists = types.MethodType(myExists, simplefile, SimpleFile)

        # Static 'exists' was overridden by the monkey patch, which accepts 0 arguments
        self.assertRaises(TypeError, simplefile.exists, 'sbrubbles')
        # Monkey patched exists
        simplefile.exists()
        self.assert_(self.duck_method_called)

        simplefile.exists = None
 def testNonExistingFile(self):
     '''Test SimpleFile class with non-existing file.'''
     f = SimpleFile(self.non_existing_filename)
     self.assertEqual(f.filename(), self.non_existing_filename)
     self.assertRaises(IOError, f.open)
     self.assertEqual(f.size(), 0)
示例#6
0
 def testNonExistingFile(self):
     '''Test SimpleFile class with non-existing file.'''
     f = SimpleFile(self.non_existing_filename)
     self.assertEqual(f.filename(), self.non_existing_filename)
     self.assertRaises(IOError, f.open)
     self.assertEqual(f.size(), 0)
示例#7
0
 def testCallingInstanceMethod(self):
     '''Call instance method.'''
     f1 = SimpleFile(self.non_existing_filename)
     self.assertFalse(f1.exists())
     f2 = SimpleFile(self.existing_filename)
     self.assertTrue(f2.exists())
示例#8
0
 def testCallingStaticMethodWithInstance(self):
     '''Call static method using instance of class.'''
     f = SimpleFile(self.non_existing_filename)
     self.assertTrue(f.exists(self.existing_filename))
     self.assertFalse(f.exists(self.non_existing_filename))
示例#9
0
 def testCallingStaticMethodWithClass(self):
     '''Call static method using class.'''
     self.assertTrue(SimpleFile.exists(self.existing_filename))
     self.assertFalse(SimpleFile.exists(self.non_existing_filename))
示例#10
0
 def testDuckPunchingStaticNonStaticMethod(self):
     f = SimpleFile(self.existing_filename)
     f.exists = lambda: "Meee"
     self.assertEqual(f.exists(), "Meee")
示例#11
0
 def __init__(self, filename):
     SimpleFile.__init__(self, filename)
 def testDuckPunchingStaticNonStaticMethod(self):
     f = SimpleFile(self.existing_filename)
     f.exists = lambda : "Meee"
     self.assertEqual(f.exists(), "Meee")
 def testCallingInstanceMethod(self):
     '''Call instance method.'''
     f1 = SimpleFile(self.non_existing_filename)
     self.assertFalse(f1.exists())
     f2 = SimpleFile(self.existing_filename)
     self.assert_(f2.exists())
 def testCallingStaticMethodWithInstance(self):
     '''Call static method using instance of class.'''
     f = SimpleFile(self.non_existing_filename)
     self.assert_(f.exists(self.existing_filename))
     self.assertFalse(f.exists(self.non_existing_filename))
 def testCallingStaticMethodWithClass(self):
     '''Call static method using class.'''
     self.assert_(SimpleFile.exists(self.existing_filename))
     self.assertFalse(SimpleFile.exists(self.non_existing_filename))
示例#16
0
 def __init__(self, filename):
     SimpleFile.__init__(self, filename)