??? UnitTest? Pytest?? ? ?? ??? ??? ??? ?????. ? ? ??? ??? ??? ??? ??? ?? ????? ?? ????? ???? ??? ?? ? ?????.
def test_negative_deposit(self): # Arrange a = BankAccount(1) # Act outcome = a.deposit(-100) # Assert self.assertFalse(outcome)
? ??? ????? ???? ???? ????? ?????? ??? ?? ???. ??? ?? ???? ???? ??? ??? ?? ???? ???? ??? ????. ?? Python?? ?? ????? ???? ?? ??? ??? ?? ? Unittest ? Pytest ? ??? ?? ? ????.
- istqb ctfl syllabus 2018
?? ???, ???? ?? ???? ??? ???? ???? ????? ???? ??? ??? ?? ??? ???? ????? ???? ??? ?? ???? ?? ???? ????.
???
???
???
?? ???
?? ??. ?? ???? ????? ???? ??? ??? ??? ?? ???? ??????.
??? Python ???? ?? ??? ?? ? ? ????.
? ?????? ???? ???? ???? ?? ??? ??? ?????. ?? ??? ??? ?? ???? ?????? ??? ?????.
<,>? ?? ?? ??? ? ?? ??? ?????. ??? test_negative_deposit? ????? ?? ?? ????. ??, AssertionError? ?? ??? ???????? true? ??? ???? ??? ???? true? ????? ?? ?????.
Pytest ?? ? ??>
? ?????
??? UnitTest? Pytest?? ? ?? ??? ??? ??? ?????. ? ? ??? ??? ??? ??? ??? ?? ????? ?? ????? ???? ??? ?? ? ?????.
??? ? ????. ????? ???? ????? ???? ?? ???? ?????. ???? ???? ???? ??? ???? ??????.
<.> ???? ???????. ??? ??? ??? ??? ?? ?? ??? ???????.
??? unittest.testcase? ?? ??? ? testbankoperations?? ???? ??? ????. ?? ???, ??? ??? ??? ??? ??? ????. unittest.testcase class?? ?? ?? ???? ???? ??????.
unittest ? ??? ?? ??? ??
<.> ??, example.py? ?? ?? ??? ???? ??? ?????. ??? ??? ??????
import unittest
class BankAccount:
def __init__(self, id):
self.id = id
self.balance = 0
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
return True
return False
def deposit(self, amount):
self.balance += amount
return True
class TestBankOperations(unittest.TestCase):
def test_insufficient_deposit(self):
# Arrange
a = BankAccount(1)
a.deposit(100)
# Act
outcome = a.withdraw(200)
# Assert
self.assertFalse(outcome)
import unittest
class BankAccount:
def __init__(self, id):
self.id = id
self.balance = 0
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
return True
return False
def deposit(self, amount):
self.balance += amount
return True
?? ?? ???? ?? ?? ???? ???? ??? ??????.
class TestBankOperations(unittest.TestCase):
def test_insufficient_deposit(self):
# Arrange
a = BankAccount(1)
a.deposit(100)
# Act
outcome = a.withdraw(200)
# Assert
self.assertFalse(outcome)
?? ???! Pytest? ???? ? ?? ???? ??? ???. Pytest? ??? ?? ??? ??
python -m unittest example.py
???? Test_? ????? _test.py? ??? ??? ???? ?????. Pytest? ?? ???? ? ?? ?? ?????? ??? ??? ????.
??? Test_Bank.py?? ??? ???? ??? ????. ??? ? ?? ??? ??? ????? :
<code>.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK</code>
? ??> <<> ?? def test_negative_deposit(self):
# Arrange
a = BankAccount(1)
# Act
outcome = a.deposit(-100)
# Assert
self.assertFalse(outcome)
? ??? UnitTest ? Pytest? ??? Python ?? ??? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!
??? ???? ??
???? ?? ??? ??? ?? AI ?? ?
???? ?? ???? ??? AI ?????.
AI ? ???
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!
???? ?? ?? ?? ???
??? ??, ???? ?? ????.
??? PHP ?? ?? ??
??? ? ?? ??
? ??? ?? ?? ?????(SublimeText3)
???? Python ?? ?? ?????? ?? ????, "??? ?????, ?? ??"? ???? ??? ??? ??? ?? ??? ?????. 1. ???? ?? ? ??? ?? ?????. ?? ???? ?? ??? ???? ??? ? ? ????. ?? ??, Spoke () ?? ???? ??? ??? ?? ??? ?? ????? ?? ??? ??? ????. 2. ???? ?? ???? ??? ??? ?????? Draw () ???? ???? ????? ?? ???? ?? ??? ???? ??? ???? ?? ?? ?? ??? ????? ?? ?? ????? ?? ?????. 3. Python ?? ???? ???????. ?? ???? ??? ???? ?? ???? ??? ????? ??? ?? ???? ??? ???? ????. ??? ??? ??? ???? ? ??? "?? ??"??????. 4. ???? ? ???? ?? ??? ?????
???? __iter __ () ? __next __ () ???? ???? ?????. ???? ??? ? ??? ????, ?? ???? ?? ??? ??? ???? ?????. 1. ???? ?? () ?? ? ??? ??? ???? ? ?? ??? ?? ? ?? ???? ??? ????. 2. ???? ?? ??? ???? ??? ???? ???? ???? ???? ?? ???? ?????. 3. ???? ???? ?? ??? ?? ? ? ? ??? ?? ? ???????? ? ? ??? ?? ??? ??? ???? ?? ? ? ???? ??????. ?? : ??? ?? ???? ??? ???? ????. ???? ?? ?? ? ??? ?????? ???? ? ?? ?? ? ? ????.
API ??? ??? ??? ?? ??? ???? ???? ???? ????. 1. Apikey? ?? ??? ?? ????, ????? ?? ?? ?? URL ?? ??? ?????. 2. Basicauth? ?? ???? ??? Base64 ??? ??? ??? ??? ????? ?????. 3. OAUTH2? ?? Client_ID ? Client_Secret? ?? ??? ?? ?? ?? ??? BearEtroken? ???????. 4. ?? ??? ???? ?? ?? ?? ???? ????? ???? ?? ?? ? ????. ???, ??? ?? ??? ??? ???? ?? ??? ???? ???? ?? ?????.
Assert? ????? ???? ???? ?? ? ???? ??? ???? ??? ?? ?? ????. ??? ??? ??? ?? ??? ?????, ?? ?? ?? ??, ?? ?? ?? ?? ?? ?? ??? ????? ?? ?? ??? ?? ???? ??? ? ??? ??? ??? ??? ?? ???????. ?? ??? ???? ?? ?? ???? ?? ????? ??? ? ????.
????? ??? ? ??? ??? ?? ??? ???? ??? zip () ??? ???? ????.? ??? ?? ??? ???? ?? ??? ?? ????. ?? ??? ???? ?? ?? itertools.zip_longest ()? ???? ?? ?? ? ??? ?? ? ????. enumerate ()? ???? ??? ???? ?? ? ????. 1.zip ()? ???? ????? ?? ??? ??? ??? ?????. 2.zip_longest ()? ???? ?? ??? ?? ? ? ???? ?? ? ????. 3. Enumental (Zip ())? ??? ??? ????? ??? ???? ???? ?? ???? ?? ? ????.
inpython, iteratorsareobjectsthatlowloppingthroughcollections __ () ? __next __ ()
typehintsinpythonsolvetheproblemombiguityandpotentialbugsindynamicallytypedcodebyallowingdevelopscifyexpectiontypes. theyenhancereadability, enablearylybugdetection ? improvetoomingsupport.typehintsareaddedusingaColon (:) forvariblesAndAramete
Python? ???? ????? ???? API? ???? Fastapi? ?????. ?? ??? ?? ????? ?????? ??? ??? ??? ???? ?? ? ? ????. Fastapi ? Asgi Server Uvicorn? ?? ? ? ????? ??? ??? ? ????. ??? ??, ?? ?? ?? ? ???? ?????? API? ???? ?? ? ? ????. Fastapi? ??? HTTP ??? ???? ?? ?? ? Swaggerui ? Redoc Documentation Systems? ?????. ?? ??? ?? URL ?? ??? ?? ? ??? ??, ?? ?? ??? ???? ???? ?? ?? ??? ??? ? ????. Pydantic ??? ???? ??? ?? ???? ???? ????? ? ??? ? ? ????.