Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trunk fmt and check #6

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches:
- main
- trunk-merge/**
pull_request:
branches:
- main
- trunk-merge/**

jobs:
trunk:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Trunk Check
uses: trunk-io/trunk-action@v1
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.trunk
build
install
8 changes: 8 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*out
*logs
*actions
*notifications
plugins
user_trunk.yaml
user.yaml
shims
2 changes: 2 additions & 0 deletions .trunk/configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
10 changes: 10 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
11 changes: 11 additions & 0 deletions .trunk/configs/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154
disable=SC2250
disable=SC2320
disable=SC2181
disable=SC2086

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
10 changes: 10 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
33 changes: 33 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 0.1
cli:
version: 1.9.1
plugins:
sources:
- id: trunk
ref: v0.0.17
uri: https://github.com/trunk-io/plugins
lint:
enabled:
- actionlint@1.6.24
- black@23.3.0
- git-diff-check
- gitleaks@8.16.3
- isort@5.12.0
- markdownlint@0.34.0
- prettier@2.8.8
- ruff@0.0.265
- shellcheck@0.9.0
- shfmt@3.5.0
- taplo@0.7.0
- yamllint@1.31.0
runtimes:
enabled:
- go@1.19.5
- node@18.12.1
- python@3.10.8
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# workflow-tutorial

Tutorial repo, that helps to setup github workflows.
1 change: 1 addition & 0 deletions magic_python/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# trunk-ignore-all(ruff/F401)
from .core import my_magic_function
4 changes: 4 additions & 0 deletions magic_python/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sys

import numpy as np


def my_magic_function(x, y):
return np.log(x) + np.log(y)


def main(argv):
if len(argv) == 0:
print("Usage: python core.py number1 [number2 [,,.]]")
Expand All @@ -15,5 +18,6 @@ def main(argv):
magic_result = my_magic_function(magic_result, value)
print(magic_result)


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
27 changes: 16 additions & 11 deletions magic_python/tests/test_my_magic.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import pytest
import numpy as np
# We want numpy to give us expections
np.seterr(all='raise')
import pytest

import magic_python

# We want numpy to give us expections
np.seterr(all="raise")


def test_values():
result = magic_python.my_magic_function(17., 45.)
expected_result = np.log(17.) + np.log(45.)
result = magic_python.my_magic_function(17.0, 45.0)
expected_result = np.log(17.0) + np.log(45.0)
assert result == expected_result


def test_math():
result = magic_python.my_magic_function(14., 72.)
expected_result = np.log(14. *72.)
result = magic_python.my_magic_function(14.0, 72.0)
expected_result = np.log(14.0 * 72.0)
# with pytest.raises(AssertionError):
# assert expected_result == result
assert pytest.approx(expected_result, 1e-6) == result


def test_test_negative():
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(-1, 23.)
magic_python.my_magic_function(-1, 23.0)
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(5, -23.)
magic_python.my_magic_function(5, -23.0)
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(0, 2.)
magic_python.my_magic_function(0, 2.0)
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(7, 0.)
magic_python.my_magic_function(7, 0.0)
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ requires = ["setuptools>=60", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
testpaths = [
"magic_python/tests",
]
testpaths = ["magic_python/tests"]
48 changes: 23 additions & 25 deletions src/tests/test_sum.sh.in
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
#!/bin/bash



# Let's test that execution without arguments should fail
`@CMAKE_CURRENT_BINARY_DIR@/main`
@CMAKE_CURRENT_BINARY_DIR@/main
# Test the return code of the execution to not be 0
if [ $? -eq 0 ]; then
exit -1
if [[ $? -eq 0 ]]; then
exit 1
fi

# Test some basic summation
result=`@CMAKE_CURRENT_BINARY_DIR@/main 3.14`
result=$(@CMAKE_CURRENT_BINARY_DIR@/main 3.14)
echo $result

# Check that return code is 0
if [ ! $? -eq 0 ]; then exit -1; fi
if [ ! "$result" = "3.14" ]; then
exit -2
if [[ ! $? -eq 0 ]]; then exit 1; fi
if [[ $result != "3.14" ]]; then
exit 2
fi

result=`@CMAKE_CURRENT_BINARY_DIR@/main 0.1 0.5`
result=$(@CMAKE_CURRENT_BINARY_DIR@/main 0.1 0.5)
echo $result

# Check that return code is 0
if [ ! $? -eq 0 ]; then exit -1; fi
if [ ! "$result" = "0.6" ]; then
exit -2
if [[ ! $? -eq 0 ]]; then exit 1; fi
if [[ $result != "0.6" ]]; then
exit 2
fi

result=`@CMAKE_CURRENT_BINARY_DIR@/main 0.1 -0.1`
result=$(@CMAKE_CURRENT_BINARY_DIR@/main 0.1 -0.1)
echo $result

# Check that return code is 0
if [ ! $? -eq 0 ]; then exit -1; fi
if [ ! "$result" = "0" ]; then
exit -2
if [[ ! $? -eq 0 ]]; then exit 1; fi
if [[ $result != "0" ]]; then
exit 2
fi

result=`@CMAKE_CURRENT_BINARY_DIR@/main 0.1 -0.15 0.5`
result=$(@CMAKE_CURRENT_BINARY_DIR@/main 0.1 -0.15 0.5)
echo $result

# Check that return code is 0
if [ ! $? -eq 0 ]; then exit -1; fi
if [ ! "$result" = "0.45" ]; then
exit -2
if [[ ! $? -eq 0 ]]; then exit 1; fi
if [[ $result != "0.45" ]]; then
exit 2
fi

result=`@CMAKE_CURRENT_BINARY_DIR@/main -0.1 -0.15 0.05`
result=$(@CMAKE_CURRENT_BINARY_DIR@/main -0.1 -0.15 0.05)
echo $result

# Check that return code is 0
if [ ! $? -eq 0 ]; then exit -1; fi
if [ ! "$result" = "-0.2" ]; then
exit -2
if [[ ! $? -eq 0 ]]; then exit 1; fi
if [[ $result != "-0.2" ]]; then
exit 2
fi
Loading