Skip to content

Commit

Permalink
Improved testing infrastructure (#455)
Browse files Browse the repository at this point in the history
* Create test_reported_bugs.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in f081cd3 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update test_reported_bugs.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in fcc2caf according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update test_reported_bugs.py

Signed-off-by: Ian Hunter <[email protected]>

* Update util.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in e6dae70 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update util.py

Signed-off-by: Ian Hunter <[email protected]>

* Update test_cli.py

Signed-off-by: Ian Hunter <[email protected]>

* Update __main__.py

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update __main__.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in ebb3e83 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update __main__.py

Signed-off-by: Ian Hunter <[email protected]>

* Update __main__.py

Signed-off-by: Ian Hunter <[email protected]>

* Update __main__.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in b93a981 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update __main__.py

Signed-off-by: Ian Hunter <[email protected]>

* Update test_reported_bugs.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in 3392f0c according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update test_reported_bugs.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in dde2bd4 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update test_reported_bugs.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in cb5ea35 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update test_core.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update test_core.yml

Signed-off-by: Ian Hunter <[email protected]>

* Delete tests/python/test_package.py

Signed-off-by: Ian Hunter <[email protected]>

* Update util.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in 247476f according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #455

---------

Signed-off-by: Ian Hunter <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
ianfhunter and deepsource-autofix[bot] authored Dec 2, 2023
1 parent 2de7cff commit d61f400
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 65 deletions.
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

0 comments on commit d61f400

Please sign in to comment.