小编Tar*_*lla的帖子

Mocha beforeEach vs执行前

我最近遇到了一个无法解释的问题.我在这些测试中有很多代码,所以我会尽力在这里捕获这个想法

我的测试看起来像:

describe('main page', function(){
  beforeEach(function(done){
    addUserToMongoDb(done);   // #1
  });

  afterEach(function(done){
    removeUserFromMongoDb(done);
  });

  context('login', function(){
     it('should log the user in, function(){
       logUserIn(user_email);  // #2 - This line requires the user from the beforeEach
     });
  });

  context('preferences', function(){
    before(function(done){    //#3
       logUserInBeforeTest(user_email);
     });

    it('should show the preferences', function(){
       doCheckPreferences(); // #4
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

问题是,beforeEach #1运行正常.我可以看到它发生在数据库和测试#2传递中.

但是,首选项上下文中的测试#4失败,因为它无法找到用户登录它们#3.

似乎上下文before在describe之前执行beforeEach,导致它们失败.如果我移动logUserInit块中它工作正常.

什么可能导致这个?

mocha.js node.js

50
推荐指数
3
解决办法
5万
查看次数

如何在python版本Windows之间切换

我试图在 python 版本3.6.63.7.0Windows之间切换。我试过了py -3.6.6,没有用。在 中寻找选项py -h,没有找到。我看到了几个在 python 版本之间切换2.x和在文件开头3.x添加的答案#!python3

我可以通过上下移动路径变量来在这些之间切换,但我想知道是否有一个选项可以在版本之间切换,cmd就像brew switch python version在 IOS中一样。

谢谢你。

python windows

8
推荐指数
2
解决办法
9125
查看次数

java中整数数组的优先级队列

我想比较以下数组的第二个元素:

int[][] intervals = new int[][]{new int[]{0, 30},new int[]{5, 10},new int[]{15, 20}};
Run Code Online (Sandbox Code Playgroud)

我的优先级队列与自定义比较器:

PriorityQueue<int[]> heap = new PriorityQueue(intervals.length, (a, b) -> a[1] - b[1]);
Run Code Online (Sandbox Code Playgroud)

但我收到以下 2 个错误:

Line 8: error: array required, but Object found
        PriorityQueue<Integer[]> heap = new PriorityQueue(intervals.length, (a, b) -> a[1] - b[1]);
                                                                                       ^
Line 8: error: array required, but Object found
        PriorityQueue<Integer[]> heap = new PriorityQueue(intervals.length, (a, b) -> a[1] - b[1]);
                                                                                             
Run Code Online (Sandbox Code Playgroud)

java heap priority-queue min-heap

8
推荐指数
2
解决办法
2万
查看次数

未找到 H2 数据库错误:90146。启动时未创建 H2 数据库

刚刚从 spring 初始化程序创建了一个简单的 spring-boot 项目。我去添加一个本地 h2 db 进行测试,但无法登录。似乎它在启动时无法创建测试数据库,但无法弄清楚为什么会这样。

spring:
  h2:
    console:
      enabled: true
      path: /h2
  datasource:
    url: jdbc:h2:mem:testdb;
    username: sa
    password:
    driver-class-name: org.h2.Driver
    platform: h2
  jpa:
    show-sql: true
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        dialect=org:
          hibernate:
            dialect:
              H2Dialect: org.hibernate.dialect.H2Dialect
Run Code Online (Sandbox Code Playgroud)

Database "mem:testdb" not found, and IFEXISTS=true, so we cant auto-create it [90146-199] 90146/90146

h2 spring-boot

5
推荐指数
4
解决办法
2万
查看次数

Python 返回 elif 语句

我试图检查传递的数字是否是有效的完美平方

return True if(math.sqrt(num)%2 == 0 or \
              (math.sqrt(num)+1) % 2 == 0 ) else False
Run Code Online (Sandbox Code Playgroud)

我想知道是否可以通过将 if 语句分成两部分来写得更好,例如

return True if(math.sqrt(num)%2 == 0) 
            elif ((math.sqrt(num)+1) % 2 == 0 ) 
            else False
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我如何在这里使用 elif 或者是否有更好的方法。

谢谢。

python

2
推荐指数
1
解决办法
8482
查看次数

标签 统计

python ×2

h2 ×1

heap ×1

java ×1

min-heap ×1

mocha.js ×1

node.js ×1

priority-queue ×1

spring-boot ×1

windows ×1