Skip to content

Commit

Permalink
Merge branch 'fix--filelines-attribute-removal' of github.com:AstuteS…
Browse files Browse the repository at this point in the history
…ource/chasten into fix--filelines-attribute-removal
  • Loading branch information
Poiuy7312 committed Nov 3, 2023
2 parents 9027877 + 7db5951 commit 84d2c2b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 48 deletions.
22 changes: 11 additions & 11 deletions .chasten/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ checks:
pattern: './/ClassDef'
count:
min: 1
max: 50
max: null
- name: "all-function-definition"
code: "AFD"
id: "F001"
pattern: './/FunctionDef'
count:
min: 1
max: 200
- name: "non-test-function-definition"
max: null
- name: "dummy-test-non-test-function-definition"
code: "NTF"
id: "F002"
pattern: './/FunctionDef[not(contains(@name, "test_"))]'
count:
min: 40
max: 1000
- name: "single-nested-if"
min: null
max: null
- name: "dummy-test-single-nested-if"
code: "SNI"
id: "CL001"
pattern: './/FunctionDef/body//If'
count:
min: 1
max: 100
- name: "double-nested-if"
min: null
max: null
- name: "dummy-test-double-nested-if"
code: "DNI"
id: "CL002"
pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]'
count:
min: 1
max: 15
min: null
max: null
19 changes: 3 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ on:
# This job performs all necessary checks
jobs:
build:
# Use the latest version of Ubuntu on MacOS and Windows
# Use the latest version of Ubuntu, MacOS, and Windows
# Use the latest and most stable version of Python
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
- name: Install Pip
if: always()
run: |
pip install -U pip
python -m pip install --upgrade pip
# Install poetry
- name: Install Poetry
if: always()
Expand All @@ -75,7 +76,6 @@ jobs:
if: always()
run: |
poetry run chasten analyze chasten --config $PWD/.chasten/ --debug-level ERROR --debug-dest CONSOLE --search-path .
# Run the tests
- name: Run Tests
if: always()
Expand All @@ -95,16 +95,3 @@ jobs:
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
CURRENT_GITHUB_STEP_SUMMARY="\`\`\`\n$(cat coverage.txt)\n\`\`\`"
echo "$CURRENT_GITHUB_STEP_SUMMARY" >> $GITHUB_STEP_SUMMARY
# Create the Coverage Badge
- name: Make Badge
uses: schneegans/[email protected]
with:
# GIST_TOKEN is a GitHub personal access token with scope "gist".
auth: ${{ secrets.GIST_TOKEN }}
gistID: 5300aa276fa9261b2b21b96c3141b3ad
filename: covbadge.json
label: Coverage
message: ${{ env.total }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.total }}
8 changes: 4 additions & 4 deletions chasten/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def check_match_count(
if min_value is not None and max_value is not None:
return is_in_closed_interval(count, min_value, max_value)
# at this point, only one of the values might not be None
# if min_value is not None, then confirm that it is less than or equal
# if min_value is not None, then confirm that it is greater than or equal
if min_value is not None:
if count <= min_value:
if count >= min_value:
return True
# if max_value is not None, then confirm that it is greater than or equal
# if max_value is not None, then confirm that it is less than or equal
if max_value is not None:
if count >= max_value:
if count <= max_value:
return True
# if none of those conditions were true, then the count is not
# between the minimum and the maximum value, inclusively
Expand Down
7 changes: 4 additions & 3 deletions chasten/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import uuid
from datetime import datetime
from pathlib import Path
from typing import List, Union
from typing import List, Optional, Union

from pyastgrep import search as pyastgrepsearch # type: ignore
from pydantic import BaseModel
from pydantic.types import conint

from chasten import debug

Expand Down Expand Up @@ -67,8 +68,8 @@ class Check(BaseModel):
id: str
name: str
description: str = ""
min: Union[None, int] = 0
max: Union[None, int] = 0
min: Optional[conint(ge=0)] = 0 # type: ignore
max: Optional[conint(ge=0)] = 0 # type: ignore
pattern: str
passed: bool
matches: list[Match] = []
Expand Down
32 changes: 28 additions & 4 deletions chasten/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,43 @@
"anyOf": [
{
"type": "object",
"properties": {"min": {"type": "integer"}},
"properties": {
"min": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
}
},
"required": ["min"],
},
{
"type": "object",
"properties": {"max": {"type": "integer"}},
"properties": {
"max": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
}
},
"required": ["max"],
},
{
"type": "object",
"properties": {
"min": {"type": "integer"},
"max": {"type": "integer"},
"min": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
},
"max": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
},
},
"required": ["min", "max"],
},
Expand Down
3 changes: 2 additions & 1 deletion tests/test_constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Pytest test suite for the constants module."""

from dataclasses import FrozenInstanceError
from pathlib import Path

import pytest
from hypothesis import given, strategies
Expand Down Expand Up @@ -44,7 +45,7 @@ def test_fuzz_init(directory, configfile, checksfile, extra, yes, no): # noqa:
def test_fuzz_immutable(fs, hr):
"""Use Hypothesis to confirm that attribute's value cannot be re-assigned."""
with pytest.raises(FrozenInstanceError):
fs.Current_Directory = "/new/path"
fs.Current_Directory = str(Path("/new") / Path("path"))
with pytest.raises(FrozenInstanceError):
hr.Yes = "YES"
with pytest.raises(FrozenInstanceError):
Expand Down
9 changes: 5 additions & 4 deletions tests/test_filesystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Pytest test suite for the filesystem module."""

import pathlib
from pathlib import Path
from unittest.mock import patch

import pytest
Expand All @@ -12,31 +13,31 @@

def test_valid_directory() -> None:
"""Confirm that a valid directory is found."""
directory_str = "./tests/"
directory_str = str(Path("./tests/"))
directory = pathlib.Path(directory_str)
confirmation = filesystem.confirm_valid_directory(directory)
assert confirmation is True


def test_invalid_directory() -> None:
"""Confirm that a valid directory is found."""
directory_str = "./testsNOT/"
directory_str = str(Path("./testsNOT/"))
directory = pathlib.Path(directory_str)
confirmation = filesystem.confirm_valid_directory(directory)
assert confirmation is False


def test_valid_file() -> None:
"""Confirm that a valid directory is found."""
file_str = "./tests/test_filesystem.py"
file_str = str(Path("./tests") / Path("test_filesystem.py"))
this_file = pathlib.Path(file_str)
confirmation = filesystem.confirm_valid_file(this_file)
assert confirmation is True


def test_invalid_file() -> None:
"""Confirm that a valid directory is found."""
file_str = "./tests/test_filesystemNOT.py"
file_str = str(Path("./tests") / Path("test_filesystemNOT.py.py"))
this_file_not = pathlib.Path(file_str)
confirmation = filesystem.confirm_valid_file(this_file_not)
assert confirmation is False
Expand Down
10 changes: 5 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
pattern: './/ClassDef'
count:
min: 1
max: 10
max: null
- name: "all-function-definition"
code: "AFD"
id: "F001"
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_cli_analyze_correct_arguments_nothing_to_analyze_not_looking(tmpdir):
project_name = "testing"
# create a reference to the internal
# .chasten directory that supports testing
configuration_directory = test_one + "/.chasten"
configuration_directory = test_one / Path(".chasten")
configuration_directory_path = Path(configuration_directory)
configuration_directory_path.mkdir()
configuration_file = configuration_directory_path / "config.yml"
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_cli_analyze_correct_arguments_analyze_chasten_codebase(cwd):
project_name = "testing"
# create a reference to the internal
# .chasten directory that supports testing
configuration_directory = str(cwd) + "/.chasten"
configuration_directory = cwd / Path(".chasten")
result = runner.invoke(
main.cli,
[
Expand All @@ -144,7 +144,7 @@ def test_cli_analyze_incorrect_arguments_no_project(cwd, tmpdir):
test_one = tmpdir.mkdir("test_one")
# create a reference to the internal
# .chasten directory that supports testing
configuration_directory = str(cwd) + "/.chasten"
configuration_directory = cwd / Path(".chasten")
# call the analyze command
result = runner.invoke(
main.cli,
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_fuzz_cli_analyze_single_directory(cwd, directory):
project_name = "testing"
# create a reference to the internal
# .chasten directory that supports testing
configuration_directory = str(cwd) + "/.chasten"
configuration_directory = cwd / Path(".chasten")
result = runner.invoke(
main.cli,
[
Expand Down

0 comments on commit 84d2c2b

Please sign in to comment.