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

Various improvements #323

Merged
merged 8 commits into from
Mar 20, 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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ij_json_spaces_within_brackets = false
ij_json_wrap_long_lines = false

[{*.py,*.pyw}]
max_line_length = 84
max_line_length = 88
ij_python_align_collections_and_comprehensions = true
ij_python_align_multiline_imports = true
ij_python_align_multiline_parameters = true
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: isort/isort-action@v1.0.0
with:
sortPaths: "./tested ./tests"
- uses: psf/black@stable
with:
version: "~= 22.0"
version: "~= 23.0"
src: "./tested ./tests"
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.isort]
profile = "black"

[tool.pylint.format]
max-line-length = "88"

[tool.black]
line-length = 88
7 changes: 4 additions & 3 deletions tested/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
import sys
from argparse import ArgumentParser, FileType
from .configs import read_config
from .utils import smart_close
from .main import run

from tested.configs import read_config
from tested.main import run
from tested.utils import smart_close

parser = ArgumentParser(
description="The programming-language-agnostic educational test framework."
Expand Down
6 changes: 3 additions & 3 deletions tested/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import logging
from dataclasses import field
from pathlib import Path
from typing import Optional, Dict, IO, TYPE_CHECKING, Any
from typing import IO, TYPE_CHECKING, Any, Dict, Optional

from pydantic import BaseModel, root_validator
from pydantic.dataclasses import dataclass

from .testsuite import Suite, ExecutionMode
from .utils import smart_close, consume_shebang, get_identifier
from tested.testsuite import ExecutionMode, Suite

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [tested.testsuite](1) begins an import cycle.
from tested.utils import consume_shebang, get_identifier, smart_close

# Prevent circular imports
if TYPE_CHECKING:
Expand Down
28 changes: 20 additions & 8 deletions tested/datatypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@
Additionally, the types in this file are organized by their JSON encoding type.
They are also split in "basic types" and "advanced types".
"""
from typing import Set, Tuple, FrozenSet

from .advanced import *
from .basic import *
from .complex import *
from ..utils import get_args
from typing import FrozenSet, Set, Tuple, Union

from tested.datatypes.advanced import (
AdvancedNothingTypes,
AdvancedNumericTypes,
AdvancedSequenceTypes,
AdvancedStringTypes,
AdvancedTypes,
)
from tested.datatypes.basic import (
BasicBooleanTypes,
BasicNothingTypes,
BasicNumericTypes,
BasicObjectTypes,
BasicSequenceTypes,
BasicStringTypes,
BasicTypes,
)
from tested.datatypes.complex import ComplexExpressionTypes
from tested.utils import get_args

NumericTypes = Union[BasicNumericTypes, AdvancedNumericTypes]
StringTypes = Union[BasicStringTypes, AdvancedStringTypes]
Expand All @@ -26,13 +40,11 @@
SequenceTypes = Union[BasicSequenceTypes, AdvancedSequenceTypes]
ObjectTypes = Union[BasicObjectTypes]


SimpleTypes = Union[NumericTypes, StringTypes, BooleanTypes, NothingTypes]
ComplexTypes = Union[SequenceTypes, ObjectTypes]

AllTypes = Union[BasicTypes, AdvancedTypes]


ExpressionTypes = Union[AllTypes, ComplexExpressionTypes]
NestedTypes = Set[Tuple[ExpressionTypes, FrozenSet[ExpressionTypes]]]

Expand Down
6 changes: 3 additions & 3 deletions tested/datatypes/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from enum import Enum
from typing import Union

from .basic import (
from tested.datatypes.basic import (
BasicNothingTypes,
BasicNumericTypes,
BasicSequenceTypes,
BasicTypes,
BasicStringTypes,
BasicNothingTypes,
BasicTypes,
)


Expand Down
3 changes: 1 addition & 2 deletions tested/description_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
import os
import re
import sys

from argparse import ArgumentParser, FileType
from functools import partial
from typing import List

from mako.template import Template

from tested.configs import Bundle, DodonaConfig
from tested.languages import get_language, language_exists
from tested.languages.description_generator import TYPE_ARG, TYPE_CONFIG_NAME
from tested.testsuite import Suite
from tested.utils import smart_close
from tested.languages import get_language, language_exists

open_brackets = ("(", "[", "{")
close_brackets = {")": "(", "]": "[", "}": "{"}
Expand Down
2 changes: 1 addition & 1 deletion tested/dodona.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import dataclasses
import json
from enum import Enum
from typing import Optional, Union, Literal, IO, Type
from typing import IO, Literal, Optional, Type, Union

from pydantic import BaseModel
from pydantic.dataclasses import dataclass
Expand Down
4 changes: 2 additions & 2 deletions tested/dsl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .translate_parser import parse_dsl, translate_to_test_suite
from .ast_translator import parse_string
from tested.dsl.ast_translator import parse_string
from tested.dsl.translate_parser import parse_dsl, translate_to_test_suite
5 changes: 3 additions & 2 deletions tested/dsl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from argparse import ArgumentParser, FileType
from .translate_parser import translate_to_test_suite
from ..utils import smart_close

from tested.dsl.translate_parser import translate_to_test_suite
from tested.utils import smart_close

parser = ArgumentParser(description="Convert a DSL test suite to the JSON test suite.")
parser.add_argument(
Expand Down
31 changes: 16 additions & 15 deletions tested/dsl/ast_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,36 @@
- Properties (ie. attributes)
"""

from pydantic import ValidationError

import ast
import dataclasses
from ..datatypes import (

from pydantic import ValidationError

from tested.datatypes import (
AdvancedNothingTypes,
BasicNothingTypes,
AllTypes,
BasicSequenceTypes,
AdvancedSequenceTypes,
AllTypes,
BasicNothingTypes,
BasicObjectTypes,
BasicSequenceTypes,
)
from ..serialisation import (
Statement,
from tested.serialisation import (
Assignment,
Expression,
FunctionCall,
FunctionType,
Value,
Identifier,
NamedArgument,
serialize_from_python,
NumberType,
SequenceType,
ObjectType,
ObjectKeyValuePair,
ObjectType,
SequenceType,
Statement,
Value,
VariableType,
Identifier,
serialize_from_python,
)
from ..utils import get_args
from tested.utils import get_args


class InvalidDslError(Exception):
Expand Down Expand Up @@ -112,7 +113,7 @@ def _convert_assignment(node: ast.Assign) -> Assignment:

if not type_:
raise InvalidDslError(
"Could deduce the type of the variable for assignment: add a type annotation."
f"Could not deduce the type of variable {variable.id}: add a type annotation."
)

return Assignment(variable=variable.id, expression=value, type=type_)
Expand Down
43 changes: 22 additions & 21 deletions tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
import json
from logging import getLogger
from pathlib import Path
from typing import Callable, Dict, List, Optional, TextIO, TypeVar, Union

import yaml
from jsonschema import Draft7Validator
from pydantic.json import pydantic_encoder

import json
from logging import getLogger
from pathlib import Path
from typing import Dict, List, Union, Callable, TextIO, TypeVar, Optional
from .ast_translator import parse_string
from ..datatypes import (
from tested.datatypes import (
BasicBooleanTypes,
BasicNumericTypes,
BasicObjectTypes,
BasicSequenceTypes,
BasicStringTypes,
)
from ..serialisation import (
Value,
NothingType,
StringType,
from tested.dsl.ast_translator import parse_string
from tested.serialisation import (
BooleanType,
ExceptionValue,
NothingType,
NumberType,
SequenceType,
ObjectType,
ObjectKeyValuePair,
ExceptionValue,
ObjectType,
SequenceType,
StringType,
Value,
)
from ..testsuite import (
from tested.testsuite import (
Context,
EmptyChannel,
ExceptionOutputChannel,
ExitCodeOutputChannel,
FileUrl,
GenericTextEvaluator,
MainInput,
Output,
Suite,
MainInput,
Tab,
Testcase,
TextData,
TextOutputChannel,
ValueOutputChannel,
ExitCodeOutputChannel,
TextData,
EmptyChannel,
ExceptionOutputChannel,
)
from ..utils import recursive_dict_merge
from tested.utils import recursive_dict_merge

logger = getLogger(__name__)

Expand Down Expand Up @@ -268,7 +269,7 @@ def _convert_dsl(dsl_object: YamlObject) -> Suite:
else:
assert isinstance(dsl_object, dict)
namespace = dsl_object.get("namespace")
config = _deepen_config_level(dsl_object.get("config"), {})
config = _deepen_config_level(dsl_object, {})
tab_list = dsl_object["tabs"]
tabs = _convert_dsl_list(tab_list, config, _convert_tab)

Expand Down
Loading