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

code testing fixes #32

Merged
merged 1 commit into from
Nov 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
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
ignore = E501
exclude =
.git,
__pycache__,
docs/source/conf.py,
old,
build,
dist
max-complexity = 10
77 changes: 77 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# The format of this file isn't really documented; just use --generate-rcfile

[Messages Control]
# C0111: Don't require docstrings on every method
# C0301: Handled by pep8
# C0325: Parens are required on print in py3x
# F0401: Imports are check by other linters
# W0511: TODOs in code comments are fine.
# W0142: *args and **kwargs are fine.
# W0622: Redefining id is fine.

# TODO(browne): fix these in the future
# C0103: invalid-name
# E1101: no-member
# E0231: missing whitespace after ','
# R0201, no-self-use
# R0204: redefined-variable-type
# R0902: too-many-instance-attributes
# R0912: too-many-branches
# R0913: too-many-arguments
# R0914: too-many-locals
# R0915: too-many-statements
# W0110: deprecated-lambda
# W0141: bad-builtin
# W0201: attribute-defined-outside-init
# W0212: protected-access
# W0401: wildcard-import
# W0603: global-statement
# W0612: unused-variable
# W0613: unused-argument
# W0621: redefined-outer-name
# W0703: broad-except
disable=C0111,C0301,C0325,F0401,W0511,W0142,W0622,C0103,E1101,E0231,R0201,R0204,R0902,R0912,R0913,R0914,R0915,W0110,W0141,W0201,W0401,W0603,W0212,W0612,W0613,W0621,W0703

[Basic]
# Variable names can be 1 to 31 characters long, with lowercase and underscores
variable-rgx=[a-z_][a-z0-9_]{0,30}$

# Argument names can be 2 to 31 characters long, with lowercase and underscores
argument-rgx=[a-z_][a-z0-9_]{1,30}$

# Method names should be at least 3 characters long
# and be lowecased with underscores
method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$

# Module names matching manila-* are ok (files in bin/)
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(manila-[a-z0-9_-]+))$

# Don't require docstrings on tests.
no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$

[Format]
max-line-length=100

[Design]
max-public-methods=100
min-public-methods=0
max-args=6

[Variables]
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
# _ is used by our localization
additional-builtins=_

[Similarities]
# Minimum lines number of a similarity.
min-similarity-lines=10

# Ignore comments when computing similarities.
ignore-comments=yes

# Ignore docstrings when computing similarities.
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=yes
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
VIRTUALENV ?= ~/.virtualenv
default: clean test

all: $(TARGETS)

clean: ## Clean all build files
-@echo y | pip uninstall sudoku
@rm -rf $(DOCS)/_build
@find . -name *.pyc -delete
@rm -rf build sudoku.egg* dist

.PHONY: test dist help

test: ## Run all tests
@ruff check .
@pytest

dist: ## Create a distribution
@python setup.py sdist --formats=gztar bdist_wheel

dev: ## Install this package for development
@pip install -e .

dev_env: ## Install the dev env
@python -m pip install flake8 pytest ruff
@python -m pip install ipykernel

virtualenv: $(VIRTUALENV)/sudoku/bin/activate
virtualenv $(VIRTUALENV)/sudoku

help: ## Shows help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'
@echo ""
4 changes: 3 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(manila-[a-z0-9_-]+))$
# Don't require docstrings on tests.
no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$

[FORMAT]
max-line-length=100

[Design]
max-public-methods=100
min-public-methods=0
max-args=6

[Variables]

# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
# _ is used by our localization
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ pandas==2.1.3
torch==2.1.1
torchvision==0.16.1
tqdm==4.66.1
pytest==7.4.3
flake8==6.1.0
16 changes: 9 additions & 7 deletions src/sudoku/reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@


def read_matrix(filename):
"""Read a matrix from a filename.

Note: wraps generic get_matrix method.
"""

Expand All @@ -17,16 +19,16 @@ def get_matrix(content):
Empty values are either 0 or . This is a fairly robust parser.
"""

if type(content) == str: # split textblob into list of lines
if isinstance(content, str): # split textblob into list of lines
content = content.splitlines()

lines = []
for line in content:
new_line = line.split("#")[0] # first remove comments starting with an #
new_line = new_line.strip() # Strip any leading or trailing whitespace
new_line = new_line.replace(".", "0") # dots are zero's
new_line = new_line.replace(",", "") # comma's are separators
new_line = new_line.replace(" ", "") # spaces are separators
new_line = line.split("#")[0] # first remove comments starting with an #
new_line = new_line.strip() # Strip any leading or trailing whitespace
new_line = new_line.replace(".", "0") # dots are zero's
new_line = new_line.replace(",", "") # comma's are separators
new_line = new_line.replace(" ", "") # spaces are separators
if new_line:
new_line = [int(x) for x in new_line]
lines.append(new_line)
Expand Down
40 changes: 20 additions & 20 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@
"""

example1_list = [
[0,0,0,0,0,0,0,9,2],
[0,0,0,1,0,0,0,4,0],
[9,0,0,2,4,0,0,0,7],
[8,0,0,7,0,0,1,5,0],
[6,5,0,9,0,1,0,7,8],
[0,7,4,0,0,8,0,0,6],
[3,0,0,0,9,5,0,0,1],
[0,8,0,0,0,6,0,0,0],
[7,9,0,0,0,0,0,0,0]
[0, 0, 0, 0, 0, 0, 0, 9, 2],
[0, 0, 0, 1, 0, 0, 0, 4, 0],
[9, 0, 0, 2, 4, 0, 0, 0, 7],
[8, 0, 0, 7, 0, 0, 1, 5, 0],
[6, 5, 0, 9, 0, 1, 0, 7, 8],
[0, 7, 4, 0, 0, 8, 0, 0, 6],
[3, 0, 0, 0, 9, 5, 0, 0, 1],
[0, 8, 0, 0, 0, 6, 0, 0, 0],
[7, 9, 0, 0, 0, 0, 0, 0, 0]
]

example2_list = [
[0,6,0,0,0,0,1,9,0],
[0,0,2,6,1,0,0,0,4],
[7,0,1,0,0,0,0,0,0],
[0,0,0,0,7,0,0,1,0],
[0,0,6,0,8,3,0,0,0],
[5,4,0,0,6,0,0,0,3],
[0,8,0,0,2,7,0,3,9],
[0,0,0,4,0,0,0,7,8],
[0,0,0,0,0,0,4,0,0]
[0, 6, 0, 0, 0, 0, 1, 9, 0],
[0, 0, 2, 6, 1, 0, 0, 0, 4],
[7, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 7, 0, 0, 1, 0],
[0, 0, 6, 0, 8, 3, 0, 0, 0],
[5, 4, 0, 0, 6, 0, 0, 0, 3],
[0, 8, 0, 0, 2, 7, 0, 3, 9],
[0, 0, 0, 4, 0, 0, 0, 7, 8],
[0, 0, 0, 0, 0, 0, 4, 0, 0]
]


def test_example1():
m = reader.get_matrix(example1)
assert len(m) == 9
assert m[0] == [0,0,0,0,0,0,0,9,2]
assert m[0] == [0, 0, 0, 0, 0, 0, 0, 9, 2]
assert m == example1_list


def test_example1_alt():
m = reader.get_matrix(example1_alt)
assert m == example1_list
Expand Down
Loading