示例#1
0
    def test_makeNote_default_writes(self, file_mock):
        doggo = Doggo("Jake")
        doggo.make_note()

        file_mock.assert_called_once_with("note.txt", 'w')
        file_mock("note.txt",
                  'w').write.assert_called_once_with("Something suspicious!")
示例#2
0
class DoggoTest(unittest.TestCase):
    def setUp(self):
        self.simple_doggo = Doggo("Jake")

    def test_doggoName_nameSet_returnsName(self):
        self.assertEqual(self.simple_doggo.name, "Jake")

    def test_doggoName_complexNameSet_returnsName(self):
        doggo = Doggo("Mr. Puppet")
        self.assertEqual(doggo.name, "Mr. Puppet")

    def test_doggoName_nameSetEmptyString_raisesError(self):
        with self.assertRaises(ValueError):
            doggo = Doggo("")

    def test_doggoName_nameSetNotAlphabetic_raisesError(self):
        with self.assertRaises(ValueError):
            doggo = Doggo("!!!")

    def test_doggoName_nameChanged_raisesError(self):
        doggo = Doggo("Something in line")
        with self.assertRaises(Exception):
            doggo.name = "Something new"

    def test_sound_soundSet_returnSound(self):
        self.simple_doggo.sound = "bark"
        self.assertEqual(self.simple_doggo.sound, "bark")

    def test_sound_default_exist(self):
        self.assertEqual(self.simple_doggo.sound, "Bark!")

    def test_sound_empty_raisesError(self):
        with self.assertRaises(ValueError):
            self.simple_doggo.sound = ""

    def test_doggoNumLegs_default_greaterThanOrEqual0(self):
        self.assertGreaterEqual(self.simple_doggo.num_legs, 0)

    def test_doggoNumLegs_setLessThan0_raisesError(self):
        with self.assertRaises(ValueError):
            self.simple_doggo.num_legs = -1

    @patch('builtins.print')
    def test_bark_default_prints(self, print_mock):
        self.simple_doggo.bark()
        print_mock.assert_called_once_with("Jake barks: Bark!")

    @patch.object('builtins.print')
    def test_growl_default_prints(self, print_mock):
        self.simple_doggo.growl()
        print_mock.assert_called_once_with("Jake: growl!")
示例#3
0
 def setUp(self):
     self.simple_doggo = Doggo("Jake")
示例#4
0
 def test_doggoName_nameChanged_raisesError(self):
     doggo = Doggo("Something in line")
     with self.assertRaises(Exception):
         doggo.name = "Something new"
示例#5
0
 def test_doggoName_nameSetNotAlphabetic_raisesError(self):
     with self.assertRaises(ValueError):
         doggo = Doggo("!!!")
示例#6
0
 def test_doggoName_nameSetEmptyString_raisesError(self):
     with self.assertRaises(ValueError):
         doggo = Doggo("")
示例#7
0
 def test_doggoName_complexNameSet_returnsName(self):
     doggo = Doggo("Mr. Puppet")
     self.assertEqual(doggo.name, "Mr. Puppet")
示例#8
0
 def test_doggoName_nameSet_returnsName(self):
     doggo = Doggo("Jake")
     self.assertEqual(doggo.name, "Jake")
示例#9
0
    def test_bark_default_prints(self, print_mock):
        doggo = Doggo("Jake")
        doggo.bark()

        self.assertListEqual(print_mock.mock_calls,
                             [call("Jake barks: Bark!")])
示例#10
0
 def test_doggoNumLegs_setLessThan0_raisesError(self):
     doggo = Doggo("Jake")
     with self.assertRaises(ValueError):
         doggo.num_legs = -1
示例#11
0
 def test_doggoNumLegs_default_greaterThanOrEqual0(self):
     doggo = Doggo("Jake")
     self.assertGreaterEqual(doggo.num_legs, 0)
示例#12
0
 def test_sound_empty_raisesError(self):
     doggo = Doggo("Jake")
     with self.assertRaises(ValueError):
         doggo.sound = ""
示例#13
0
 def test_sound_default_exist(self):
     doggo = Doggo("Jake")
     self.assertEqual(doggo.sound, "Bark!")
示例#14
0
 def test_sound_soundSet_returnSound(self):
     doggo = Doggo("Jake")
     doggo.sound = "bark"
     self.assertEqual(doggo.sound, "bark")