小编Syl*_*are的帖子

在闪亮的应用程序中调整Flex仪表板尺寸

有什么方法可以在闪亮的应用程序中使Flexdashboard仪表更大吗?

我试图更改UI中的宽度和高度,但这只是在仪表板上移动它。它不会使它变大。

library(shiny)
library(flexdashboard)

fluidRow(column(
         width =  12,
           gaugeOutput('Scale', width = "800px", height = "400px")
       )
)
Run Code Online (Sandbox Code Playgroud)

r shiny flexdashboard

6
推荐指数
1
解决办法
399
查看次数

Travis ci上的Python3模块导入失败

我已经制作了一个用于测试我的项目的Python 3脚本.该脚本具有以下结构:

main.py
myRequest.py
external/
  requests/
    __init__.py
    many files of the library...
Run Code Online (Sandbox Code Playgroud)

当我运行python3 main.py文件时myRequest.py导入.在那个档案里面,我做到了import external.requests as reqs.这对我有用,也传递给Travis CI

但是,当我将上述文件放在项目的文件夹test中时,Travis CI作业找不到该模块:

ImportError: No module named external.requests.
Run Code Online (Sandbox Code Playgroud)

当我尝试在在线IDE(c9,Ubuntu 14.04,Python 3.4.0)中运行脚本时,它能够导入它.在c9,我尝试过from .external import requests as reqs但它提出了一个:

SystemError: Parent module '' not loaded, cannot perform relative import.
Run Code Online (Sandbox Code Playgroud)

添加空__init__.py文件或运行python3 -m main.py没有做任何事情.

我应该怎么做才能在Travis CI取得成功?

import python-3.x travis-ci

5
推荐指数
1
解决办法
659
查看次数

如何在python中的不同实现中使用相同的单元测试?

我正在开发回答相同问题但使用不同算法的多个功能。

因此,所有功能的相同输入应生成相同的输出,这就是为什么我不得不使用相同的单元测试,而不必使用相同的逻辑创建多个测试的原因。

我使用的是Python unittest框架,我想使用一个抽象测试类来用函数变量定义泛型测试,以便可以用要在另一个普通测试类中测试的泛型实例化该泛型函数。但是似乎我无法在子类中实例化函数变量。

因此,这里是一个示例抽象类,其中包含针对多个功能的通用测试。

class AbstractTestCase():

    def test_generic_input_one(self):
        result = self.function("input 1")
        self.assertFalse(result)

    def test_generic_input_two(self):
        result = self.function("input 2")
        self.assertTrue(result)
Run Code Online (Sandbox Code Playgroud)

在这里,您将拥有的特定测试类,该类function_a继承了AbstractTestCase该类的通用测试并实现了自己的测试。

class TestsFunctionA(AbstractTestCase, unittest.TestCase):

    def setUp(self):
        self.function = function_a

    def test_specific_input(self):
        result = self.assertTrue(self.function("specific input"))
        self.assertTrue(result)
Run Code Online (Sandbox Code Playgroud)

我很确定它可以完成,但是我似乎找不到一个示例来了解如何实现它。我想避免代码重复。

最简单,最好的方法是什么?

python tdd automated-tests unit-testing python-unittest

5
推荐指数
1
解决办法
1857
查看次数

使用 springmockk 时 Kotlintest 不执行测试

我试图为我的 kotlin spring 应用程序编写一个集成测试。为此,我使用了 kotlintest 框架。因为我需要在我的应用程序中模拟其中一个 bean,所以我还添加了带有 springmockk 扩展的 mockk。添加 springmockk 扩展后,不再执行测试。

我注意到只要将 springmockk 添加到 gradle testImplement 依赖项中就会发生这种情况,它甚至不必导入到应用程序代码本身中。

buildscript {
    ext.kotlin_version = '1.3.21'
    ext.kotlintestVersion='3.4.2'
    ext.spring_boot_version='2.1.4.RELEASE'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBoot_version")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlin_version")
    }
}

...

dependencies {
    ...
    testImplementation("org.springframework.boot:spring-boot-starter-test:$springBoot_version") {
    testImplementation("io.kotlintest:kotlintest-runner-junit5:$kotlintestVersion")
    testImplementation("io.kotlintest:kotlintest-extensions-spring:$kotlintestVersion")
    testImplementation("io.mockk:mockk:1.9.3")
//    testImplementation("com.ninja-squad:springmockk:2.0.0")
}
Run Code Online (Sandbox Code Playgroud)

在 github 上,我发现了一个问题,遗憾的是已经关闭了,但没有任何将这两个框架一起使用的正确方法:https : //github.com/Ninja-Squad/springmockk/issues/26

编辑:

这是一个示例测试,它在使用 mockkito 时有效,但在使用 springmockk 时无效。

@ExtendWith(SpringExtension::class)
@SpringBootTest
@AutoConfigureMockMvc
@WithMockUser(authorities = ["ROLE_TESTUSER"])
internal class MockTest : AnnotationSpec() {

    override fun listeners() = listOf(SpringListener)

    @Autowired
    lateinit …
Run Code Online (Sandbox Code Playgroud)

spring unit-testing kotlin kotlintest mockk

5
推荐指数
1
解决办法
518
查看次数

使用 Spring Boot 运行单元测试,出现“无可运行方法”错误

我正在使用 Spring boot 运行单元测试,但出现了一个奇怪的no runnable错误。测试通过了,但是在所有测试成功结束之后,我突然得到这个奇怪的错误:

java.lang.Exception: No runnable methods

at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:137)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
Run Code Online (Sandbox Code Playgroud)

我该如何解决?为什么 Spring boot 在我的测试中寻找可运行程序?

这是我的代码的示例

package ca.bell.uc.hello.world

import org.junit.Assert
import org.junit.jupiter.api.Test
import org.junit.runner.RunWith
import org.springframework.test.context.junit4.SpringRunner


@RunWith(SpringRunner::class)
internal class example {

    @Test
    fun f() {
        Assert.assertTrue(true)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误的屏幕截图:

在此输入图像描述

谢谢

PS 这是 Kotlin

spring unit-testing kotlin spring-boot

5
推荐指数
1
解决办法
2976
查看次数

如何遍历字符串列表并在 Kotlin 中连接它们?

我有一个字符串列表,例如:

listOf("1", "2", "3", "4", "+", "3")
Run Code Online (Sandbox Code Playgroud)

我想连接以便我只得到数字:"1234". 我首先尝试使用有效的 for 循环。

但是我想知道 Kotlin 是否有一种方法可以使用一条很好的一行来衬托整个事情,例如:

val myList = listOf("1", "2", "3", "4", "+", "3")
someConcatenationFunction(myList) // returns "1234"
Run Code Online (Sandbox Code Playgroud)

string list kotlin

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

如何在R语言的列表中将字符(0)转换为NA?

如何使用R语言转换character(0)为NA列表?

例:

a = list("a", "character(0)", "b", "c")
Run Code Online (Sandbox Code Playgroud)

至

a = list("a", "NA", "b", "c")
Run Code Online (Sandbox Code Playgroud)

谢谢.

r list

3
推荐指数
1
解决办法
4858
查看次数

尝试将 swagger-codegen 包含在 gradle kotlindsl 中

我正在尝试swagger codegen在使用 gradle (kotlin) 构建的项目中工作。

我的参考是这里的示例: https: //github.com/int128/gradle-swagger-generator-plugin,它是在Gradle groovy版本中制作的。

现在情况build.gradle.kts如下:

repositories {
    jcenter()
}

plugins {
    java
    id("org.springframework.boot") version "2.1.2.RELEASE"
    id("io.spring.dependency-management") version "1.0.6.RELEASE"
    id("org.hidetake.swagger.generator") version "2.16.0"
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation ("io.swagger:swagger-annotations:1.5.21")
    swaggerCodeGen("io.swagger:swagger-codegen-cli:2.3.1")

    // Use JUnit test framework
    testImplementation ("junit:junit:4.12")
}

swaggerSources {
    petstore {
        inputFile = file('petstore.yaml')
        code {
            language = 'spring'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但 IntelliJ 不喜欢谈论 swagger 的台词:

智能错误

我是 gradle 的新手,所以我不明白我应该做什么。swaggerCodeGen 应该是一个函数吗?这个函数应该在哪里导入?swaggerSources应该从哪里进口?

gradle kotlin swagger openapi

3
推荐指数
1
解决办法
4866
查看次数

kotlin 程序错误:jar 文件中没有主清单属性

我写了一个简单的 kotlin helloworld 程序 hello.kt

fun main(args: Array<String>) {
    println("Hello, World!")
}
Run Code Online (Sandbox Code Playgroud)

然后我用kotlinc编译

$kotlinc hello.kt -include-runtime -d hello.jar
Run Code Online (Sandbox Code Playgroud)

没有错误并且生成了 hello.jar。当我运行它时

$java -jar hello.jar
Run Code Online (Sandbox Code Playgroud)

它说 hello.jar 中没有主要清单属性

$no main manifest attribute, in hello.jar
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚这个问题。我的 kotlin 版本是 1.3.40,JDK 版本是 1.8.0

kotlin

3
推荐指数
2
解决办法
2797
查看次数

Azure Cloud 版本“secrets-store.csi.k8s.io/v1alpha1”中的类型“SecretProviderClass”没有匹配项

我正在 azure 云中工作,想要使用 Azure Azure / Secrets-store-csi-driver-provider-azure中的文档添加一个简单的 ServiceProviderClass替换secret,keyvaultName和tenantId

apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
kind: SecretProviderClass
metadata:
  name: azure-kvname
spec:
  provider: azure
  parameters:
    usePodIdentity: "false"         # [OPTIONAL] if not provided, will default to "false"
    keyvaultName: "kvname"          # the name of the KeyVault
    cloudName: ""          # [OPTIONAL for Azure] if not provided, azure environment will default to AzurePublicCloud 
    objects:  |
      array:
        - |
          objectName: secret1
          objectType: secret        # object types: secret, key or cert
          objectVersion: ""         # [OPTIONAL] object …
Run Code Online (Sandbox Code Playgroud)

azure azure-security azure-secrets

3
推荐指数
1
解决办法
4402
查看次数

未使用express-jwt获取req.user对象

这是我的设置express-jwt:

exports.requireSignin = expressJwt({
   secret: process.env.JWT_SECRET,
   algorithms: ["HS256"], 
   userProperty: "auth"
 });
Run Code Online (Sandbox Code Playgroud)

我正在使用它访问一条秘密路线进行测试,但是我没有req.user在此处的路线中获取该属性。它会产生一个空对象(未定义)。

router.get("/secret",requireSignin,(req, res) => {
    res.json({
        message: req.user,
    });
});
Run Code Online (Sandbox Code Playgroud)

我正在使用 Postman 来测试并发送带有授权标头的令牌作为不记名令牌。

node.js express jwt reactjs express-jwt

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

通过 TCP 端口发送简单消息

我真的很想通过 tcp 发送一条非常简单的消息,让两个 kotlin 程序(服务器和客户端)相互通信,相互发送短字符串。

我有一个非常简单的服务器代码:

fun main(args : Array<String>) {
    val server = ServerSocket(5000)
    println("Server is running on port ${server.localPort}")

    val socket = server.accept()

    print("connected to client: "+ socket.inetAddress.toString())   
    val text = BufferedReader(InputStreamReader(socket.inputStream)).readLine()
}
Run Code Online (Sandbox Code Playgroud)

这对于客户来说:

fun main(args: Array<String>) {
    val socket = Socket("localhost", 5000)

    PrintWriter(socket.outputStream, true).write("text")
}
Run Code Online (Sandbox Code Playgroud)

我的想法是,我首先运行服务器,然后运行客户端,然后从客户端向服务器发送一些消息(也可能相反)。我现在尝试从本教程中获取当前的内容(https://sylhare.github.io/2020/04/07/Kotlin-tcp-socket-example.html),但发现很难弄清楚什么去做

任何帮助深表感谢

tcp kotlin

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

ansible"目录/ usr/lib /不是空的,拒绝转换它"

我正在尝试使用ansible创建符号链接:

__CODE__

而且我得到了这个:

__CODE__

python debian ansible

0
推荐指数
1
解决办法
1159
查看次数