在Matlab命令窗口中输入:
syms f;
s = 2*pi*f*j;
s
Run Code Online (Sandbox Code Playgroud)
返回
s =
pi*f*2*j
Run Code Online (Sandbox Code Playgroud)
为什么pi不计算为3.141592 ...?我输入命令窗口的代码出了什么问题?
我想测试异常是否运行良好JUnit5.
例如,假设我测试队列.
public class ArrayCircleQueue {
.
.
.
public void enQueue(char item) {
if (isFull()) {
throw new IndexOutOfBoundsException("Queue is full now!");
} else {
itemArray[rear++] = item;
}
}
}
Run Code Online (Sandbox Code Playgroud)
识别TestClass
class ArrayCircleQueueTest {
.
.
.
@org.junit.jupiter.api.Test
void testEnQueueOverflow() {
for (int i=0; i<100; i++) {
queue.enQueue('c'); # test for 10-size queue. It should catch exception
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在谷歌搜索它,但只有答案JUnit4:
@Test(expected=NoPermissionException.class)
但它不起作用JUnit5.
我怎么处理它?
在Django,我可以像这样命名每个模型领域(韩语):
description = models.CharField("??", max_length=100, blank=True)
image = ImageField("???", upload_to=upload_location)
Run Code Online (Sandbox Code Playgroud)
但如果是ForeignKey,它不起作用.
album = models.ForeignKey("??", Album)
Run Code Online (Sandbox Code Playgroud)
为什么它不起作用ForeignKey?
Django: 1.9.7 / Python3.5.1
视图.py
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
class OrderPayCheckView(View):
@csrf_exempt
def post(self, request, *args, **kwargs):
return JsonResponse(
data={
"valid": False,
}
)
Run Code Online (Sandbox Code Playgroud)
当我POST通过 向这个 url发送请求时POSTMAN,它显示,
403 Forbidden-CSRF authentication Fail有点东西(我真的想显示所有错误,但语言是韩语)
我在我的测试服务器中测试了它,它有自己的 url。
为什么会发生?
In [3]: import numpy as np
In [4]: b = pd.DataFrame(np.array([
...: [1,np.nan,3,4],
...: [np.nan, 4, np.nan, 4]
...: ]))
In [13]: b
Out[13]:
0 1 2 3
0 1.0 NaN 3.0 4.0
1 NaN 4.0 NaN 4.0
Run Code Online (Sandbox Code Playgroud)
我想找到Nan值存在的列名和索引。
例如,“b有NaN在价值index 0, col1,index 0, col0,index 1 col2。
我试过的:
1
In [14]: b[b.isnull()]
Out[14]:
0 1 2 3
0 NaN NaN NaN NaN
1 NaN NaN NaN NaN
Run Code Online (Sandbox Code Playgroud)
=> 我不知道为什么它显示 …
根据airflow连接管理页面,我们可以使用环境变量来创建连接:
export AIRFLOW_CONN_MY_PROD_DATABASE='my-conn-type://login:password@host:port/schema?param1=val1¶m2=val2'
Run Code Online (Sandbox Code Playgroud)
所以,我下载了官方的docker-compose.yml:
$ curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.2.0/docker-compose.yaml'
Run Code Online (Sandbox Code Playgroud)
并添加了连接的环境变量,如下所示:
...
47 image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.2.0}
48 # build: .
49 environment:
50 &airflow-common-env
51 AIRFLOW_CONN_MY_PROD_DB: my-conn-type://login:password@host:port/schema?param1=val1¶m2=val2
52 AIRFLOW__CORE__EXECUTOR: CeleryExecutor
...
Run Code Online (Sandbox Code Playgroud)
然后,我使用以下方式加载所有容器docker-compose up并有权访问airflow-worker服务:
$ docker-compose exec airflow-worker /bin/bash
Run Code Online (Sandbox Code Playgroud)
并查看所有连接列表:
airflow@52d9c6ab9309:/opt/airflow$ airflow connections list
Run Code Online (Sandbox Code Playgroud)
但它说:
No data found
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我不明白为什么我们需要mock在一些测试用例中,特别是像下面这样:
主要.py
import requests
class Blog:
def __init__(self, name):
self.name = name
def posts(self):
response = requests.get("https://jsonplaceholder.typicode.com/posts")
return response.json()
def __repr__(self):
return '<Blog: {}>'.format(self.name)
Run Code Online (Sandbox Code Playgroud)
测试.py
import main
from unittest import TestCase
from unittest.mock import patch
class TestBlog(TestCase):
@patch('main.Blog')
def test_blog_posts(self, MockBlog):
blog = MockBlog()
blog.posts.return_value = [
{
'userId': 1,
'id': 1,
'title': 'Test Title,
'body': 'Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy\ lies a small unregarded …Run Code Online (Sandbox Code Playgroud)