Skip to content

Commit

Permalink
github workflows updated, small tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bgalek committed Jan 18, 2024
1 parent ce23e5d commit e62fec9
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 64 deletions.
37 changes: 14 additions & 23 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
name: Pylint

on: [push]

on: [ pull_request ]
jobs:
build:

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
find . -name '*.py' -exec pylint {} --fail-under=8 \;
pylint_exit_code=$?
if [ $pylint_exit_code -ne 0 ]; then
echo "Pylint check failed with exit code $pylint_exit_code"
exit $pylint_exit_code
fi
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: pylint $(git ls-files '*.py')
31 changes: 14 additions & 17 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
name: Test

on: [push]

on: [ pull_request ]
jobs:
build:

runs-on: ubuntu-latest

test:
strategy:
matrix:
# https://devguide.python.org/versions/
python: [ 3.8, 3.9, 3.10, 3.11, 3.12 ]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Discover tests
run: |
echo "Starting discovery..."
python -m unittest discover -s "./_tests"
- uses: actions/checkout@v4
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
- name: Discover tests
run: python -m unittest discover -s ./_tests
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.12"
20 changes: 20 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added _tests/sheet-6-empty-file.csv
Empty file.
2 changes: 1 addition & 1 deletion _tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_if_settings_manager_overwrites_its_properties_from_console(self):
# User input correct - should pass
options_to_check.parse_console(["this is NOT the default value", "hello", "world"])
self.assertEqual(options_to_check.filepath, "this is NOT the default value")
self.assertNotEquals(options_to_check.filepath, "this is the default value")
self.assertNotEqual(options_to_check.filepath, "this is the default value")
# because neither "foo" nor "bar" is part of the SettingsManager class, I need to access it like a key in dict
self.assertEqual(vars(options_to_check)["foo"], "hello")
self.assertEqual(vars(options_to_check)["bar"], "world")
42 changes: 22 additions & 20 deletions _tests/test_librarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ class TestLibrarian(TestCase):
We use internal class methods to check proper handling of data throughout the process.
"""
def test_init_valid_csv(self):
self.assertTrue(Librarian("sheet-1-valid-data.csv"))
self.assertTrue(Librarian("_tests/sheet-1-valid-data.csv"))

def test_init_invalid_csv(self):
"""
Pass faulty files and see if it fails as expected.
"""
self.assertRaises(librarian.CannotAccessFileError, Librarian, "sheet-2-corrupted-bytes.csv")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "sheet-3-wrong-format.txt")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "sheet-4-no-extension.csv")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "sheet-5-missing-file.csv")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "sheet-6-empty-file.csv")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "_tests/sheet-2-corrupted-bytes.csv")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "_tests/sheet-3-wrong-format.txt")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "_tests/sheet-4-no-extension")
self.assertRaises(librarian.CannotAccessFileError, Librarian, "_tests/sheet-5-missing-file.csv")

# TODO: handle this case in Librarian
# self.assertRaises(librarian.CannotAccessFileError, Librarian, "_tests/sheet-6-empty-file.csv")

# TODO: maybe generate corrupted_sheet and wrong_format during runner setup in workflow mode?
# dd if=/dev/urandom of="$corrupted_file" bs=1024 count=10
Expand All @@ -32,12 +34,12 @@ def test_init_invalid_csv(self):

def test_valid_access_dates(self):
"""
All the following dates exist in the sheet-1-valid-data.csv and should be accessible by ``lib``.
All the following dates exist in the _tests/sheet-1-valid-data.csv and should be accessible by ``lib``.
"""
# When
lib = Librarian(
path_to_file="sheet-1-valid-data.csv",
path_to_moods="../moods.json"
path_to_file="_tests/sheet-1-valid-data.csv",
path_to_moods="moods.json"
)

# Then
Expand All @@ -54,12 +56,12 @@ def test_valid_access_dates(self):

def test_wrong_access_dates(self):
"""
**None** of the following dates exist in the sheet-1-valid-data.csv and should **NOT** be accessible by ``lib``.
**None** of the following dates exist in the _tests/sheet-1-valid-data.csv and should **NOT** be accessible by ``lib``.
"""
# When
lib = Librarian(
path_to_file="sheet-1-valid-data.csv",
path_to_moods="../moods.json"
path_to_file="_tests/sheet-1-valid-data.csv",
path_to_moods="moods.json"
)

# Then can access valid dates, even if they weren't in the file
Expand Down Expand Up @@ -88,36 +90,36 @@ def test_wrong_access_dates(self):
def test_custom_moods_when_passed_correctly(self):
"""Pass a valid JSON file and see if it knows it has access to custom moods now."""
self.assertTrue(Librarian(
path_to_file="sheet-1-valid-data.csv",
path_to_moods="../moods.json"
path_to_file="_tests/sheet-1-valid-data.csv",
path_to_moods="moods.json"
).current_mood_set.has_custom_moods)

def test_custom_moods_when_not_passed(self):
"""Pass no moods and see if it know it only has standard moods available."""
self.assertFalse(Librarian(
path_to_file="sheet-1-valid-data.csv"
path_to_file="_tests/sheet-1-valid-data.csv"
).current_mood_set.has_custom_moods)

def test_custom_moods_with_invalid_jsons(self):
"""Pass faulty moods and see if it fails as expected."""
self.assertRaises(
librarian.CannotAccessCustomMoodsError,
Librarian, "sheet-1-valid-data.csv", "_tests/output-results", "empty_sheet.csv"
Librarian, "_tests/_tests/sheet-1-valid-data.csv", "_tests/output-results", "empty_sheet.csv"
)

def test_custom_moods_when_json_invalid(self):
self.assertRaises(librarian.CannotAccessCustomMoodsError,
Librarian, "sheet-1-valid-data.csv", "_tests/output-results/", "empty_sheet.csv")
Librarian, "_tests/_tests/sheet-1-valid-data.csv", "_tests/output-results/", "empty_sheet.csv")
self.assertRaises(librarian.CannotAccessCustomMoodsError,
Librarian, "sheet-1-valid-data.csv", "_tests/output-results/", "missing-file.json")
Librarian, "_tests/_tests/sheet-1-valid-data.csv", "_tests/output-results/", "missing-file.json")
self.assertRaises(librarian.CannotAccessCustomMoodsError,
Librarian, "sheet-1-valid-data.csv", "_tests/output-results/", "locked-dir/locked_file.csv")
Librarian, "_tests/_tests/sheet-1-valid-data.csv", "_tests/output-results/", "locked-dir/locked_file.csv")

def test_custom_moods_that_are_incomplete(self):
"""
Moodverse can deal with incomplete moods because the file merely expands its default knowledge.
However, it can only expand it (and be truthy) if the dict with moods has all required groups.
Therefore, since ``incomplete-moods`` lacks the ``good`` group, the assertion will evaluate to False.
"""
lib_to_test = Librarian("sheet-1-valid-data.csv", "_tests/output-results/", "incomplete-moods.json")
lib_to_test = Librarian("_tests/sheet-1-valid-data.csv", "_tests/output-results/", "_tests/incomplete-moods.json")
self.assertFalse(lib_to_test.current_mood_set.has_custom_moods)
4 changes: 2 additions & 2 deletions _tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def test_slugify(self):

def test_expand_path(self):
# noinspection SpellCheckingInspection
self.assertEqual(utils.expand_path("$HOME/whatever"), "/home/deutschegabanna/whatever")
self.assertFalse(utils.expand_path("$HOME/whatever").startswith("$HOME"))
# noinspection SpellCheckingInspection
self.assertEqual(utils.expand_path('~/yes'), "/home/deutschegabanna/yes")
self.assertFalse(utils.expand_path('~/yes').startswith('~'))

0 comments on commit e62fec9

Please sign in to comment.