Not running unit test with single quotes - unit-testing

Gradle 7.3
Kotlin 1.7.10
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
internal class MainTest {
#Test
fun `Test how work Kotlin in Junit 5`() {
Assertions.assertThat("nice").isEqualTo("nice")
}
}
I try to run this test like this:
gradle test --tests com.myproject.MainTest.`Test how work Kotlin in Junit 5`
But get error:
Command 'Test' not found, did you mean:
command 'test' from deb coreutils (8.30-3ubuntu2)
Try: sudo apt install <deb name>
> Task :app:test FAILED

Related

Automate config command in Git Bash with Python

I want to automate these commands:
echo something
git config --global user.name "myUser"
git config --global user.email "myMail#mail.com"
I did some research and saw this library in Python subprocess. But the following commands don't work:
import subprocess
subprocess.call(["echo", "something"])
subprocess.call(["git", "config", "--global", "user.name", "\"myUser\""])
subprocess.call(["git", "config", "--global", "user.email", "myMail#mail.com"])
This is my ".bat" file, where I have the Python location and the script location:
#echo off
"C:\Python27\python.exe" -c "D:\Tools\Scripts\GIT_login.py"
pause
Unfortunately, when I run the ".bat" file, I get this message:
File "<string>", line 1
D:\Tools\Scripts\GIT_login.py
↑
SyntaxError: invalid syntax
If you are running the bat on git-bash, you need to give the python file path like this:
'D://Tools/Scripts/GIT_login.py'

How can I compile with the "kotlin.test" dependency on the commandline?

High Folks,
I started to learn Kotlin and I ran into a dependency issue for "kotlin.test" on my Linux machine which I don't know to overcome:
kotlinc first_unit_test.kt -> fails
On the Kotlin webpage it is mentioned that "kotlin.test" is
under the hood, but I don't know how include and activate
it on the command line.
first_unit_test.kt:1:15: error: unresolved reference: test
import kotlin.test.Test
^
first_unit_test.kt:2:15: error: unresolved reference: test
import kotlin.test.assertTrue
^
first_unit_test.kt:6:3: error: unresolved reference: Test
#Test
^
first_unit_test.kt:9:3: error: unresolved reference: assertTrue
assertTrue("Hello" in "Hello World!")
^
Even if I include the runtime I get the same error :-(
kotlinc first_unit_test.kt -include-runtime -d first_unit.jar
Here the very small test program:
import kotlin.test.Test
import kotlin.test.assertTrue
class first_unit_test {
#Test
fun testHello()
{
assertTrue("Hello" in "Hello World!")
}
}
I also tried the "-cp" switch, but I couldn't get it to work.
Actually I want to compile and later I want to run those unit test,
and I have no clue how to make them run either ...
Okay I made some progress:
first I copied
kotlin-test.jar
kotlin-test-junit.jar
into the build folder and
I changed the build command:
kotlinc -cp ".:./kotlin-test.jar:./kotlin-test-junit.jar" first_unit_test.kt -include-runtime -d first_unit.jar
Now I have a new error for which I do not have a clue:
first_unit_test.kt:6:3: error: this class does not have a constructor
#Test
^
Why do I have to provide a constructor?
import kotlin.test.Test
import kotlin.test.assertTrue
class first_unit_test {
#Test
fun testHello()
{
assertTrue("Hello" in "Hello World!")
}
}

Running cdk synth on Azure devops pipeline gives ImportError: No module named aws_cdk

I am having below pipeline in azure devops. I have tested the cdk project on local and it works fine.
When I run the same on azure devops, it gives an error.
pipeline
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '12.x'
displayName: 'Install Node.js'
- script: |
sudo npm install -g aws-cdk
python3 -m pip3 install -r requirements.txt
pip3 install aws_cdk.aws_ec2 aws_cdk.core
cdk synth
displayName: 'npm install and build'
error
2020-09-16T09:20:50.1136286Z Installing collected packages: publication, attrs, cattrs, six, python-dateutil, zipp, importlib-resources, typing-extensions, jsii, aws-cdk.cloud-assembly-schema, aws-cdk.cx-api, aws-cdk.region-info, constructs, aws-cdk.core, aws-cdk.aws-iam, aws-cdk.aws-kms, aws-cdk.aws-cloudwatch, aws-cdk.assets, aws-cdk.aws-events, aws-cdk.aws-s3, aws-cdk.aws-s3-assets, aws-cdk.aws-logs, aws-cdk.aws-ssm, aws-cdk.aws-ec2
2020-09-16T09:20:51.0427755Z Successfully installed attrs-20.2.0 aws-cdk.assets-1.63.0 aws-cdk.aws-cloudwatch-1.63.0 aws-cdk.aws-ec2-1.63.0 aws-cdk.aws-events-1.63.0 aws-cdk.aws-iam-1.63.0 aws-cdk.aws-kms-1.63.0 aws-cdk.aws-logs-1.63.0 aws-cdk.aws-s3-1.63.0 aws-cdk.aws-s3-assets-1.63.0 aws-cdk.aws-ssm-1.63.0 aws-cdk.cloud-assembly-schema-1.63.0 aws-cdk.core-1.63.0 aws-cdk.cx-api-1.63.0 aws-cdk.region-info-1.63.0 cattrs-1.0.0 constructs-3.0.4 importlib-resources-3.0.0 jsii-1.12.0 publication-0.0.3 python-dateutil-2.8.1 six-1.15.0 typing-extensions-3.7.4.3 zipp-3.1.0
2020-09-16T09:20:55.2430033Z Traceback (most recent call last):
2020-09-16T09:20:55.2430990Z File "app.py", line 3, in <module>
2020-09-16T09:20:55.2431651Z from aws_cdk import core
2020-09-16T09:20:55.2432408Z ImportError: No module named aws_cdk
2020-09-16T09:20:55.2468987Z Subprocess exited with error 1
app.py
#!/usr/bin/env python3
from aws_cdk import core
from ec2.ec2_stack import Ec2Stack
app = core.App()
env = core.Environment(account="95XXXXXXXX174", region="us-east-1")
stack=Ec2Stack(app, "ec2",env=env)
app.synth()
Can anyone please guide me here.
Check your cdk.json file, try using python3 app.py instead of python app.py, :
{
"app": "python3 app.py"
}
I met same issue when using python app.py in cdk.json.

Flutter unit testing. error while running test

I am getting following error while running flutter unit test.
00:05 +1: ...
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart
Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error:
import of dart:mirrors with
--enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run
the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine
not prepare and launch isolate. Shell:
[ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the
engine with configuration. 00:05 +1 -1: loading
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart
[E] Failed to load
"/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart":
Shell subprocess cleanly reported an error before connecting to test
harness. Check the logs above for an error message. Test:
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart
Shell:
/home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester
Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with
--enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run
the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine
not prepare and launch isolate. Shell:
[ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the
engine with configuration. 00:05 +1 -2: loading
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart
[E] Failed to load
"/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart":
Shell subprocess cleanly reported an error before connecting to test
harness. Check the logs above for an error message. Test:
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart
Shell:
/home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester
Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with
--enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run
the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine
not prepare and launch isolate. Shell:
[ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the
engine with configuration. 00:06 +1 -3: loading
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart
[E] Failed to load
"/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart":
Shell subprocess cleanly reported an error before connecting to test
harness. Check the logs above for an error message. Test:
/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart
Shell:
/home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester
pubsec.yml
name: flutter_woocommerce
description: A new Flutter package project.
version: 0.0.1
author:
homepage:
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
dio: ^2.1.6
built_value: ^6.6.0
built_value_generator: ^6.6.0
built_collection: ^4.2.2
dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^4.0.0
build_runner: ^1.5.0
source_gen: ^0.9.4+2
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages
flutter doctor
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.35.0)
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
Tag.dart
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:flutter_woocommerce/model/util/Link.dart';
part 'Tag.g.dart';
abstract class Tag implements Built<Tag, TagBuilder> {
static Serializer<Tag> get serializer => _$tagSerializer;
int get id;
String get name;
String get slug;
#nullable
String get description;
#nullable
int get count;
#nullable
#BuiltValueField(wireName: '_links')
Link get links;
Tag._();
factory Tag([updates(TagBuilder b)]) = _$Tag;
}
Tag_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'dart:convert';
import 'package:built_collection/built_collection.dart';
import 'package:flutter_woocommerce/test_strings.dart';
import 'package:flutter_woocommerce/model/Serializers.dart';
import 'package:flutter_woocommerce/model/Tag.dart';
import 'package:flutter_woocommerce/model/util/Link.dart';
void main() {
final parsedJson = json.decode(TestStrings.TAG_JSON);
Tag tag = serializers.deserializeWith(Tag.serializer, parsedJson);
test('id', () {
expect(tag.id, 32);
});
test('name', () {
expect(tag.name, 'Telephone');
});
test('slug', () {
expect(tag.slug, 'telephone');
});
test('description', () {
expect(tag.description, '');
});
test('count', (){
expect(tag.count, 0);
});
test('_links is Link Object', () {
expect(tag.links, isInstanceOf<Link>());
});
test('_links > self is href[]', () {
expect(tag.links.self, isInstanceOf<BuiltList<Href>>());
});
test('_links > collection is href[]', () {
expect(tag.links.collection, isInstanceOf<BuiltList<Href>>());
});
test('_links > collection > href value', () {
expect(tag.links.collection.first.href, 'http://paathsala-wp.test/wp-json/wc/v2/products/tags');
});
}
The problem is that you're trying to use reflection (dart:mirror), which is not possible with Flutter because:
"Since reflection makes all code implicitly used by default, it interferes with tree shaking." Source
I believe it is related with the JSON serialization provided by the built_value_generator dart package.
It seems I have imported a wrong library in one of my model class. Once I removed the library
import 'package:built_collection/built_collection.dart';
All the tests are passing.

scope="module" does not seem to be working in pytest

I am working with pytest fixtures. My test module is as follows :
import pytest
#pytest.yield_fixture
#pytest.fixture(scope="module")
def jlt() :
print("setup executed")
yield None
print("tearing up")
def test_one(jlt) :
id = 123
assert id == 123
def test_two(jlt) :
id = 456
assert id == 456
I am executing this as follows :
py.test -v --capture=no test_jlt.py
The output is :
platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- /usr/bin/python
cachedir: ../../.cache
rootdir: /home/vandana/unix Home/pythonLearn, inifile: pytest.ini
collected 2 items
test_jlt.py::test_one setup executed
PASSEDtearing up
test_jlt.py::test_two setup executed
PASSEDtearing up
The scope="module" does not seem to be working. The fixture is getting executed for each function and not just once for the entire module.
I do not know what should be done
#pytest.yield_fixture replaces #pytest.fixture, so you should use #pytest.yield_fixture(scope="module") instead.
Note that with pytest 3.x you can simply use #pytest.fixture and use yield inside the fixture, which simplifies things a bit.