import unittest
import io
import re
from unittest import mock
import math
import copy
import inspect
import student_X as main #Replace student_X with your filename 
    
    
    
 

class ReviveTests(unittest.TestCase):

    def test_default_case(self):
        function = main.revive
        
        test = False
        try:
            incorrect = ""
            result = function.__doc__
            result = result.strip()
            test =  result != incorrect
        except:
            pass
        message = "No docstring."
        self.assertTrue(test, message)


        main.Pokemon.__eq__ = lambda x,y: x.name == y.name and x.number == y.number and x.types == y.types and x.hit_points == y.hit_points and x.max_hp == y.max_hp
        

        pyro = main.Pokemon()
        pyro.name = 'Flareon'
        pyro.number = 136
        pyro.types = ['Fire']
        pyro.hit_points = 0
        pyro.max_hp = 80

        inputs = (pyro)  #what to run the function on

        #expected answers
        correct_inputs = copy.deepcopy(inputs)
        correct_inputs.hit_points = 40
        correct_result = None
        correct_printed = ""

        #run the test
        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            if isinstance(inputs, tuple):
                result = function(*inputs)
            else:
                result = function(inputs)
        printed_output = fake_stdout.getvalue().strip()
        #test static inputs
        test = inputs == correct_inputs
        message = "Doesn't work on a fainted (0 HP) Pokemon with even max HP."
        self.assertTrue(test, message)
        test = result == correct_result
        message = "Isn't void."
        self.assertTrue(test, message)
        test = correct_printed == printed_output
        message = "Shouldn't print anything out."
        self.assertTrue(test, message)

        
        

        pyro = main.Pokemon()
        pyro.name = 'Flareon'
        pyro.number = 136
        pyro.types = ['Fire']
        pyro.hit_points = 0
        pyro.max_hp = 77

        inputs = (pyro)  #what to run the function on

        #expected answers
        correct_inputs = copy.deepcopy(inputs)
        correct_inputs.hit_points = 38
        correct_result = None
        correct_printed = ""

        #run the test
        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            if isinstance(inputs, tuple):
                result = function(*inputs)
            else:
                result = function(inputs)
        printed_output = fake_stdout.getvalue().strip()
        #test static inputs
        test = inputs == correct_inputs
        message = "Doesn't work on a fainted (0 HP) Pokemon with odd max HP."
        self.assertTrue(test, message)
        test = result == correct_result
        message = "Isn't void."
        self.assertTrue(test, message)
        test = correct_printed == printed_output
        message = "Shouldn't print anything out."
        self.assertTrue(test, message)

        
        

        pyro = main.Pokemon()
        pyro.name = 'Flareon'
        pyro.number = 136
        pyro.types = ['Fire']
        pyro.hit_points = 5
        pyro.max_hp = 77

        inputs = (pyro)  #what to run the function on

        #expected answers
        correct_inputs = copy.deepcopy(inputs)
        correct_inputs.hit_points = 5
        correct_result = None
        correct_printed = "This Flareon is not fainted."

        #run the test
        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            if isinstance(inputs, tuple):
                result = function(*inputs)
            else:
                result = function(inputs)
        printed_output = fake_stdout.getvalue().strip()
        #test static inputs
        test = inputs == correct_inputs
        message = "Doesn't work on a lucid Pokemon."
        self.assertTrue(test, message)
        test = result == correct_result
        message = "Isn't void."
        self.assertTrue(test, message)
        test = correct_printed == printed_output
        message = "Doesn't print out the correct sentence when given a lucid Pokemon."
        self.assertTrue(test, message)






        
        
if __name__ == "__main__":
    tests = ReviveTests()
    tests.test_default_case()