<commit_before>from test_base import *
from mockito import *

# TODO: add more test cases (create a base test class for both static and class methods?)

class Dog():
  @classmethod
  def bark(cls):
    return "woof!"
  
class Cat():
  @classmethod
  def meow(cls, m):
    return str(cls) + " " + str(m)

class MockitoClassMethodsTest(TestBase):   

  def tearDown(self):
    unstub() 

  def testUnstubs(self):     
    when(Dog).bark().thenReturn("miau!")
    unstub()
    self.assertEquals("woof!", Dog.bark())
  
  def testStubs(self):     
    self.assertEquals("woof!", Dog.bark())
    
    when(Dog).bark().thenReturn("miau!")
    
    self.assertEquals("miau!", Dog.bark())
    
  def testVerifiesMultipleCallsOnClassmethod(self):     
    when(Dog).bark().thenReturn("miau!")

    Dog.bark()
    Dog.bark()
    
    verify(Dog, times(2)).bark()
    
  def testFailsVerificationOfMultipleCallsOnClassmethod(self):
    when(Dog).bark().thenReturn("miau!")

    Dog.bark()
    
    self.assertRaises(VerificationError, verify(Dog, times(2)).bark)

  def testStubsAndVerifiesClassmethod(self):
    when(Dog).bark().thenReturn("miau!")
    
    self.assertEquals("miau!", Dog.bark())
    
    verify(Dog).bark()
    
  def testPreservesClassArgumentAfterUnstub(self):
    self.assertEquals("__main__.Cat foo", Cat.meow("foo"))

    when(Cat).meow("foo").thenReturn("bar")
    
    self.assertEquals("bar", Cat.meow("foo"))
    
    unstub()
    
    self.assertEquals("__main__.Cat foo", Cat.meow("foo"))<commit_msg>fixed the test to work even if run from the suite<commit_after>from test_base import *
from mockito import *

# TODO: add more test cases (create a base test class for both static and class methods?)

class Dog():
  @classmethod
  def bark(cls):
    return "woof!"
  
class Cat():
  @classmethod
  def meow(cls, m):
    return str(cls) + " " + str(m)

class MockitoClassMethodsTest(TestBase):   

  def tearDown(self):
    unstub() 

  def testUnstubs(self):     
    when(Dog).bark().thenReturn("miau!")
    unstub()
    self.assertEquals("woof!", Dog.bark())
  
  def testStubs(self):     
    self.assertEquals("woof!", Dog.bark())
    
    when(Dog).bark().thenReturn("miau!")
    
    self.assertEquals("miau!", Dog.bark())
    
  def testVerifiesMultipleCallsOnClassmethod(self):     
    when(Dog).bark().thenReturn("miau!")

    Dog.bark()
    Dog.bark()
    
    verify(Dog, times(2)).bark()
    
  def testFailsVerificationOfMultipleCallsOnClassmethod(self):
    when(Dog).bark().thenReturn("miau!")

    Dog.bark()
    
    self.assertRaises(VerificationError, verify(Dog, times(2)).bark)

  def testStubsAndVerifiesClassmethod(self):
    when(Dog).bark().thenReturn("miau!")
    
    self.assertEquals("miau!", Dog.bark())
    
    verify(Dog).bark()
    
  def testPreservesClassArgumentAfterUnstub(self):
    self.assertTrue(Cat.meow("foo").endswith("Cat foo"))

    when(Cat).meow("foo").thenReturn("bar")
    
    self.assertEquals("bar", Cat.meow("foo"))
    
    unstub()
    
    self.assertTrue(Cat.meow("foo").endswith("Cat foo"))
{'fraction_non_alphanumeric': 0.15700325732899023, 'fraction_numerical': 0.0013029315960912053, 'mean_word_length': 3.444283646888567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2734051', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1064, 'n_words': 183}