import unittest
from pyinno_gen import pyinno_gen


class Test_template_string(unittest.TestCase):
    """
    innosetup iss file canbe generated by giving jinja template string as input
    """
    def setUp(self):
        self.jinja = "hello {{name}}"
        self.argument = {"name":"its-me-abi"}
        self.expected_result = "hello its-me-abi"
        self.outputfile = "generated.iss"
        self.tmplteman = pyinno_gen.template_man(template_str=self.jinja)

    def test_string_input(self):
        self.tmplteman.set_context(self.argument)
        result = self.tmplteman.generate()
        self.assertEqual(self.expected_result,result, "jinja template string returned unexpected result ")

    def test_file_output(self):
        self.tmplteman.write_to_file({"name": "its-me-abi","Version":"1.0.1"}, self.outputfile)
        data = ""
        with open(self.outputfile, "r") as f:
            data = f.read()
        self.assertEqual(self.expected_result,data )

class Test_Innosetup_string(unittest.TestCase):
    """
    innosetup iss file canbe generated by giving jinja template string as input
    """
    def setUp(self):
        self.jinja = "hello [[name]]"
        self.argument = {"name":"its-me-abi"}
        self.expected_result = "hello its-me-abi"
        self.outputfile = "generated.iss"
        self.inno = pyinno_gen.InnoSetup(template_str=self.jinja)

    def test_string_input(self):
        result = self.inno.generate(self.argument)
        self.assertEqual(self.expected_result,result, "jinja template string returned unexpected result ")

    def test_file_output(self):
        self.inno.write_to_file({"name": "its-me-abi","Version":"1.0.1"}, self.outputfile)
        data = ""
        with open(self.outputfile, "r") as f:
            data = f.read()
        self.assertEqual(self.expected_result,data )

if __name__ == "__main__":
    unittest.main()