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

Improved testing infrastructure #455

Merged
merged 39 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f081cd3
Create test_reported_bugs.py
ianfhunter Dec 2, 2023
1a155c1
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
fff13c5
Merge branch 'main' into ianfhunter-patch-2
ianfhunter Dec 2, 2023
fcc2caf
Update test_reported_bugs.py
ianfhunter Dec 2, 2023
dd4c26b
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
6b33596
Update test_reported_bugs.py
ianfhunter Dec 2, 2023
e6dae70
Update util.py
ianfhunter Dec 2, 2023
9839edb
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
b9828e2
Update util.py
ianfhunter Dec 2, 2023
5c098bd
Update test_cli.py
ianfhunter Dec 2, 2023
8801d37
Update __main__.py
ianfhunter Dec 2, 2023
0c01059
Update Makefile
ianfhunter Dec 2, 2023
bcea452
Update target.mk
ianfhunter Dec 2, 2023
5df302a
Update target.mk
ianfhunter Dec 2, 2023
ebb3e83
Update __main__.py
ianfhunter Dec 2, 2023
d8fc9a6
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
6272fea
Update __main__.py
ianfhunter Dec 2, 2023
86bc395
Update __main__.py
ianfhunter Dec 2, 2023
b93a981
Update __main__.py
ianfhunter Dec 2, 2023
2bee7cd
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
afc4a17
Update __main__.py
ianfhunter Dec 2, 2023
3392f0c
Update test_reported_bugs.py
ianfhunter Dec 2, 2023
9f2b802
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
8e496b6
Update Makefile
ianfhunter Dec 2, 2023
cb8e064
Update Makefile
ianfhunter Dec 2, 2023
dde2bd4
Update test_reported_bugs.py
ianfhunter Dec 2, 2023
14869c3
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
b4697fa
Update Makefile
ianfhunter Dec 2, 2023
b3dd5cc
Update Makefile
ianfhunter Dec 2, 2023
961e985
Update Makefile
ianfhunter Dec 2, 2023
cb5ea35
Update test_reported_bugs.py
ianfhunter Dec 2, 2023
31c0199
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
ca8fec1
Update Makefile
ianfhunter Dec 2, 2023
fd25607
Update test_core.yml
ianfhunter Dec 2, 2023
4505539
Update Makefile
ianfhunter Dec 2, 2023
85fdd46
Update test_core.yml
ianfhunter Dec 2, 2023
3d9dfb6
Delete tests/python/test_package.py
ianfhunter Dec 2, 2023
247476f
Update util.py
ianfhunter Dec 2, 2023
42cf51b
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf
deepsource-autofix[bot] Dec 2, 2023
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
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ASAN_FLAGS= -fsanitize=address \
-fno-omit-frame-pointer -static-libasan -g
GDB_FLAGS= -g -gdwarf-5

DEBUG=0
DEBUG?=0
ifeq ($(DEBUG), 1)
# Valgrind
OPT=-O0 $(GDB_FLAGS)
Expand All @@ -65,7 +65,7 @@ endif
endif


USE_SECURE_RANDOM=0
USE_SECURE_RANDOM?=0
ifeq ($(USE_SECURE_RANDOM), 1)
#$(shell echo "Using Fast, but Cryptographically insecure random fn")
ARC4RANDOM:=-lbsd `pkg-config --libs libbsd`
Expand All @@ -76,7 +76,7 @@ endif

USE_CLT=0

YACC_FALLBACK=0
YACC_FALLBACK?=0
ifeq ($(YACC_FALLBACK), 1)
#$(shell echo USING YACC)
PARSER:=yacc
Expand All @@ -85,7 +85,7 @@ else
PARSER:=bison --yacc
endif

LEX_FALLBACK=0
LEX_FALLBACK?=0
ifeq ($(LEX_FALLBACK), 1)
#$(shell echo USING LEX)
LEXER:=lex
Expand Down Expand Up @@ -166,10 +166,7 @@ build/*/%.o:src/grammar/*/%.c
build/%.o:src/grammar/%.c
$(CC) $(SHAREDCFLAGS) -c -o $@ $^

test_no_pip : python
python3 -m pytest tests/python/ -xs

test : pip
test: pip
python3 -m pytest tests/python/ -xs

include src/*/target.mk
Expand Down
10 changes: 5 additions & 5 deletions src/python/code/gnoll/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def parse_cmdline_args(args):
return a


def main(EXPR, times, no_builtins, **kwargs):
def main(EXPR, times, no_builtins, breakdown, **kwargs):
"""
The entry point for gnoll when called via `python -m gnoll`
@param EXPR - the expression
Expand All @@ -75,10 +75,10 @@ def main(EXPR, times, no_builtins, **kwargs):
@param **kwargs - other key word arguments to be passed to gnoll.roll
"""
for _ in range(times):
_, [[result]], breakdown = gnoll.roll(EXPR,
builtins=not no_builtins,
**kwargs)
yield (breakdown[0], "-->", result) if breakdown else (result, )
_, [[result]], dice_breakdown = gnoll.roll(EXPR,
builtins=not no_builtins,
**kwargs)
yield (dice_breakdown[0], "-->", result) if breakdown else (result, )


def main_with_args(args):
Expand Down
2 changes: 1 addition & 1 deletion src/python/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python: all

pip : python
cd src/python/ ; python3 -m build
python3 -m pip install -vvv --user --find-links=src/python/dist/ --force-reinstall --ignore-installed gnoll
python3 -m pip install -vvv --user --find-links=src/python/dist/ --force-reinstall --ignore-installed src/python/
python3 -c "from gnoll import roll; roll('2')"

publish: test
Expand Down
1 change: 1 addition & 0 deletions tests/python/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


def test_cli():
print(m("1d4"))
[[r]] = m("1d4")
assert isinstance(r, int)

Expand Down
10 changes: 0 additions & 10 deletions tests/python/test_package.py

This file was deleted.

17 changes: 17 additions & 0 deletions tests/python/test_reported_bugs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import pytest


@pytest.mark.skip(reason="Known bug #444")
def test_issue_444():
"""
issue reported that the built-in/mock combination produces a segmentation fault
WARN: this is testing the pip library not the local one
"""
from gnoll import roll as gnollroll

with pytest.raises(Exception) as exc_info:
gnollroll("1d6", builtins=True, mock=1)

assert exc_info.type is None, f"Exception {exc_info.value} was raised unexpectedly"
43 changes: 2 additions & 41 deletions tests/python/util.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import importlib.util as iu
import os
import subprocess
from enum import Enum

import numpy as np

GRAMMAR_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../src/grammar"))
SRC_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../src/python/code/gnoll/"))
MK_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))

first_run = True
from gnoll import roll as gnoll_roll


class Mock(Enum):
Expand All @@ -29,45 +19,16 @@ def error_handled_by_gnoll(e):
raise AssertionError


def get_roll():
# We are explicitly using the local module here as we modify the yacc in order to mock our tests.
# This ugly logic is to bypass the fact that you might have the pip package installed
# and thus a name conflict
m = os.path.join(SRC_DIR, "__init__.py")
spec = iu.spec_from_file_location("dt", m)
dt = iu.module_from_spec(spec)
spec.loader.exec_module(dt)

dice_tower_roll = dt.roll
return dice_tower_roll


def make_all():
cmd = "make all -s -C " + MK_DIR
cmd = cmd.split(" ")
parser = subprocess.Popen(cmd, shell=False)
parser.communicate()
if parser.returncode:
raise ValueError


def roll(s,
mock_mode=Mock.NO_MOCK,
mock_const=3,
verbose=False,
squeeze=True,
builtins=False):
global first_run

if first_run:
make_all()
if mock_mode is None:
mock_mode = Mock.NO_MOCK
first_run = False

# Get module now - post make
dice_tower_roll = get_roll()
dt_return = dice_tower_roll(
dt_return = gnoll_roll(
s,
mock=mock_mode.value,
mock_const=mock_const,
Expand Down
Loading