Ok, so i believe i am missing something really obvious, but i have been trying for a long time to figure out a way and everyone who has tried to help me just tell me that i pretty much got it set up correctly for everything to work, but it doesn't no matter what test i try, i have been through so many but the most promising for now is
import unittest
from unittest import TestCase
from mock import patch
from encrdecrprog import encryption
class teststuff(TestCase):
def test_encryption(self):
with patch('__bulletin__.raw_input', return_value = 'x') as raw_input:
self.assertEqual(encryption(x), '78')
_raw_input.assert_called_once_with('x')
I stole this from python mocking raw input in unittests I just don't understand how it works, at all...
The code that i want to test is
def enprint():
print(encryption(raw_input()))
def encryption(x):
pur = ("".join("{:02x}".format(ord(c)) for c in x))
#The code for this was shamelessly stolen from https://stackoverflow.com/questions/12214801/print-a-string-as-hex-bytes
return pur
def main():
userinput = raw_input()
if userinput == "1":
enprint()
I need to figure out how to get the unittest to work, properly. I have an input which is encryption(x), this is called in another method. This input is needed without calling the other method to test it with a unittest. I need to test if the output equals something i already figured out beforehand, that x = 78, so i hashed out this code basically as clear as i can, english is not my first language so sorry if its bad.
Here is the newest try:
import unittest
from encrdecrprog import encryption
class TestStringMethods(unittest.TestCase):
def setup(self):
pass
def test_encryption(self):
self.assertEquals(encryption('x'), 78)
print self.test_encryption
if __name__ == '__main__':
unittest.main()
Also, what i expect is a test that checks weather x really equals 78. EDIT: to add i am using 2.7 python Should probably add that i use wing ide to help me spot errors with its inbuilt exception checker to help me spot what is wrong just in case it matters.