我有一个简单的方法,根据方法参数将全局变量设置为 True 或 False。
这个全局变量被调用feedback并且有一个默认值False。
当我调用时,setFeedback('y')全局变量将更改为feedback = True. 当我调用时,setFeedback('n')全局变量将更改为feedback = False.
现在我尝试使用 Python 中的 unittest 来测试它:
class TestMain(unittest.TestCase):
def test_setFeedback(self):
self.assertFalse(feedback)
setFeedback('y')
self.assertTrue(feedback)
Run Code Online (Sandbox Code Playgroud)
当我运行此测试时,出现以下错误:AssertionError: False is not true。
因为我知道该方法工作正常,所以我假设全局变量以某种方式重置。然而,由于我对Python环境还很陌生,所以我不知道我到底做错了什么。
我已经在这里读过一篇关于模拟的文章,但是由于我的方法更改了全局变量,所以我不知道模拟是否可以解决这个问题。
如果有建议,我将不胜感激。
这是代码:
主要.py:
#IMPORTS
from colorama import init, Fore, Back, Style
from typing import List, Tuple
#GLOBAL VARIABLE
feedback = False
#SET FEEDBACK METHOD
def setFeedback(feedbackInput):
"""This methods sets the feedback variable according to the given …Run Code Online (Sandbox Code Playgroud) python unit-testing python-3.x python-unittest python-unittest.mock
我有以下代码:
<form [formGroup]="meetingFormGroup">
<!-- Date Input -->
<mat-form-field>
<input
matInput
[min]="minDate"
[max]="maxDate"
[matDatepicker]="picker"
placeholder="Choose a date"
formControlName="date"
required
>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
<mat-error *ngIf="meetingFormGroup.controls['date'].hasError('required')"
>Please choose a date.</mat-error
>
<mat-error *ngIf="?????"
>Entered date is too small.</mat-error
>
</mat-form-field>
</form>
Run Code Online (Sandbox Code Playgroud)
现在在Angular Material 网站的“日期验证”部分,我阅读了以下内容:
每个验证属性都有一个可以检查的不同错误:
A value that violates the min property will have a matDatepickerMin error.
A value that violates the max property will have a matDatepickerMax error.
A value that violates the matDatepickerFilter property will have …Run Code Online (Sandbox Code Playgroud)