Skip to content

Commit

Permalink
Iterator tests are running again.
Browse files Browse the repository at this point in the history
  • Loading branch information
StrayFeral committed Jun 1, 2023
1 parent b640055 commit 5a9ec67
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions i2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Normal installation
python -m pip install .

1 change: 1 addition & 0 deletions inst.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# Editable installation
python -m pip install -e .

5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bumpversion>=0.6.0
twine>=4.0.2
mypy>=1.1.1
pytest>=7.3.1

7 changes: 7 additions & 0 deletions setup_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
python -m venv venv
source venv/bin/activate
python -m pip install -r requirements.txt

echo "Now you can run inst.sh for an editable module installation"

2 changes: 1 addition & 1 deletion src/custom_numbers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .custom_numbers import CustomNumeralSystem, CustomNumber # Saving some typing to the users
#from .custom_numbers import CustomNumeralSystem, CustomNumber # Saving some typing to the users

__version__ = "0.0.1"
__author__ = r"Evgueni Antonov ([email protected])"
10 changes: 6 additions & 4 deletions src/custom_numbers/custom_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ def valid_number(self, number: str) -> bool:
if len(number) == 0:
raise ValueError("Passed an empty string as a 'number' argument.")

# Test if string contains forbidden characters
regex_str = f"\[{self._FORBIDDENCHARACTERS}\]"
# Test if string contains forbidden characters.
# Generally I dislike the + string concatenation, but as an
# f-string the regexes triggered some warnings.
regex_str = r"[" + re.escape(self._FORBIDDENCHARACTERS) + r"]"
regex = re.compile(regex_str)
if regex.search(number):
return False

# Test if string contains any characters outside the defined set
regex_str = f"\[^{self._digits}\]"
regex_str = r"[^" + re.escape(self._digits) + r"]"
regex = re.compile(regex_str)
if regex.search(number):
return False
Expand Down Expand Up @@ -208,7 +210,7 @@ def __init__(self, numeral_system: CustomNumeralSystem, min_length: int = 0, max
if len(init_value) > 0 and (len(init_value) < min_length or (max_length > 0 and len(init_value) > max_length)):
raise ValueError("Incorrect init_value length.")

if not numeral_system.valid_number(init_value):
if len(init_value) > 0 and not numeral_system.valid_number(init_value):
raise ValueError("Invalid characters in number, which are not in the chosen numeral system.")


Expand Down
4 changes: 4 additions & 0 deletions t.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Run tests
python -m pytest tests/

8 changes: 4 additions & 4 deletions tests/test_custom_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from custom_numbers import custom_numbers as cn



# ================================================== GEARITERATOR TESTS
# Scenario 0) Invalid parameters exception test
sys3 = cn.CustomNumeralSystem("pba")
#params0_1 = [[], 0, 2] # Empty set
params0_2 = [sys3, 3, 2] # min_length > max_length
params0_3 = [sys3, 5, 10, "ppp"] # len(init_value) < min_length
params0_2 = [sys3, 3, 2] # min_length > max_length
params0_3 = [sys3, 5, 10, "ppp"] # len(init_value) < min_length
params0_4 = [sys3, 5, 10, "ppppppppppppppp"] # len(init_value) > max_length
params0_5 = [sys3, 3, 10, "pbz"] # Invalid symbol in init_value
params0_5 = [sys3, 3, 10, "pbz"] # Invalid symbol in init_value

# Scenario 1) no init_value, max_length=2, full test
params1 = [sys3, 0, 2, ""]
Expand Down
1 change: 1 addition & 0 deletions uninst.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# Uninstall
python -m pip uninstall -y custom-numbers

0 comments on commit 5a9ec67

Please sign in to comment.