def test_main(self): # Monkey patch raw_input and stdout using the mock library with patch('__builtin__.raw_input') as raw_inp: with patch('sys.stdout', new_callable=StringIO) as stdout: raw_inp.return_value = '2+3\n' calc.main() self.assertEqual(stdout.getvalue(),'5\n')
def SciCal(): loop = True while (loop): print_menu() operator = input('Enter your option\n') if (operator == 'x'): loop = False calc.main() continue oprand = float(input("Enter input\n")) if (operator == '1'): print("Result : ", 1 / oprand) input() clear() elif (operator == '2'): print("Result : ", oprand**2) input() clear() elif (operator == '3'): print("Result : ", oprand**3) input() clear() elif (operator == '4'): print("Result : ", oprand**0.5) input() clear() else: print(" Invalid Input....Try again") input() clear()
def test_main(self): # Monkey patch raw_input and stdout using the mock library with patch('__builtin__.raw_input') as stdin: with patch('sys.stdout', new_callable=StringIO) as stdout: stdin.return_value = '2+3\n' calc.main() self.assertEqual(stdout.getvalue(),'5\n')
def reader(symbols, mass, name): while True: equ = input( 'Pls enter a chemical formula or expression, enter exit to stop:') if 'exit' in equ: break elif ("*" in equ) or ('/' in equ) or ('+' in equ) or ('-' in equ) or ( '^' in equ): calc.main(equ) else: parse(equ, symbols, mass, name)
def get_table(subjects): """ Форматирование оценок :param subjects: dict словарь {"Предмет" : список оценок} :return: возврщает отформатированную строку с оценками """ message = "" for subject in subjects.keys(): message += f"{subject} : {', '.join(subjects[subject] or ' ')} \n" marks = [int(mark) for mark in subjects[subject]] message += calc.main(marks) + "\n" return message
def test_run_with_arguments(capfd): with unittest.mock.patch("sys.argv", ["calc.py", "1+3"]): main() out, _ = capfd.readouterr() assert out.strip() == "4.0"
def test_4_plus_5(self): sys.argv = ["", "4", "+", "5"] self.assertEqual(main(), 9)
def test_3_minus_9(self): sys.argv = ["", "3", "-", "9"] self.assertEqual(main(), -6)
def test_2_times_6(self): sys.argv = ["", "2", "*", "6"] self.assertEqual(main(), 12)
def test_2_times_6(): sys.argv = [ "", "2", "*", "6"] eq_(main(), 12)
def test_4_plus_5(): sys.argv = [ "", "4", "+", "5"] eq_(main(), 9)
def test_3_minus_9(): sys.argv = [ "", "3", "-", "9"] eq_(main(), -6)
import cProfile import pstats from io import BytesIO as StringIO import calc def my_func(): result = [] for i in range(10000): result.append(i) return result pr = cProfile.Profile() pr.enable() calc.main() pr.disable() s = StringIO() print(s) ps = pstats.Stats(pr, stream=s).sort_stats('tottime') ps.print_stats() with open('test.txt', 'w+') as f: f.write(s.getvalue())
import tbltrim import calc RETRIM = False if (RETRIM): tbltrim.main() compiled_mats = calc.main() with open('results.csv', 'w', encoding='utf-8') as resfile: for char in compiled_mats.keys(): mastery = compiled_mats[char][0] if len(mastery) > 0: mastery = "S" + "/".join(str(skill) for skill in mastery) else: mastery = "N/A" mats = compiled_mats[char][1].keys() matDetails = [] for key in mats: matDetails.append([ compiled_mats[char][1][key], compiled_mats[char][2][key], compiled_mats[char][3][key] ]) resfile.write(char + "," + mastery + "," + ",".join( [str(item) for numNeeded in matDetails for item in numNeeded]) + "\n")