Skip to content

Commit

Permalink
fixed all test scenarios - returns OK
Browse files Browse the repository at this point in the history
  • Loading branch information
DeutscheGabanna committed Jan 17, 2024
1 parent 0238b1b commit b1e7b4f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
7 changes: 2 additions & 5 deletions _tests/test_dated_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def test_bare_minimum_dated_entries(self):
# When
bare_minimum_dated_entry = DatedEntry(
time="1:49 AM",
mood="vaguely ok",
override_mood_set={
"neutral": ["vaguely ok"]
}
mood="vaguely ok"
)

# Then
Expand All @@ -54,4 +51,4 @@ def test_bare_minimum_dated_entries(self):
self.assertTrue(bare_minimum_dated_entry.activities, [])

def test_insufficient_dated_entries(self):
self.assertRaises(ValueError, DatedEntry, "2:00", mood="", known_moods={"neutral": ["vaguely ok"]})
self.assertRaises(ValueError, DatedEntry, time="2:00", mood="")
5 changes: 3 additions & 2 deletions _tests/test_librarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def test_custom_moods_when_json_invalid(self):

def test_custom_moods_that_are_incomplete(self):
"""
Moodverse can deal with incomplete moods because the file merely expands its default knowledge
Therefore it will still be truthy.
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")
self.assertFalse(lib_to_test.current_mood_set.has_custom_moods)
9 changes: 7 additions & 2 deletions _tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
class TestUtils(TestCase):
def test_slugify(self):
# no need to check if slug is a valid tag
# noinspection SpellCheckingInspection
self.assertEqual(utils.slugify("ConvertThis to-------a SLUG", False), "convertthis-to-a-slug")
# noinspection SpellCheckingInspection
self.assertEqual(utils.slugify("Zażółć gęślą jaźń ", False), "zażółć-gęślą-jaźń")
self.assertEqual(utils.slugify(" Multiple spaces between words", False), "multiple-spaces-between-words")
self.assertEqual(utils.slugify(" Multiple spaces between words", False), "multiple-spaces-between-words")
# noinspection SpellCheckingInspection
self.assertEqual(utils.slugify("Хлеба нашего повшеднего", False), "хлеба-нашего-повшеднего")

# check if the slug is a valid tag
Expand All @@ -23,5 +26,7 @@ def test_slugify(self):
utils.slugify("Digits at the end of the string are also ok 456", True)

def test_expand_path(self):
# noinspection SpellCheckingInspection
self.assertEqual(utils.expand_path("$HOME/whatever"), "/home/deutschegabanna/whatever")
self.assertEqual(utils.expand_path('~'), "/home/deutschegabanna")
# noinspection SpellCheckingInspection
self.assertEqual(utils.expand_path('~/yes'), "/home/deutschegabanna/yes")
16 changes: 10 additions & 6 deletions dated_entries_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from __future__ import annotations

from typing import Optional
import re
import logging

Expand Down Expand Up @@ -119,7 +120,7 @@ class DatedEntriesGroup(utils.Core):
"""
_instances = {}

def __new__(cls, date: str, current_mood_set: Moodverse):
def __new__(cls, date: str, current_mood_set: Moodverse = Moodverse()):
# Check if an instance for the given date already exists
if date in cls._instances:
return cls._instances[date]
Expand All @@ -129,10 +130,11 @@ def __new__(cls, date: str, current_mood_set: Moodverse):
cls._instances[date] = instance
return instance

def __init__(self, date, current_mood_set: Moodverse):
def __init__(self, date, current_mood_set: Moodverse = Moodverse()):
"""
:raises InvalidDateError: if the date string is deemed invalid by :class:`Date`
:param date: The date for all child entries within.
:param current_mood_set: Use custom :class:`Moodverse` or default if not provided.
"""
self.__logger = logging.getLogger(self.__class__.__name__)

Expand All @@ -151,15 +153,13 @@ def __init__(self, date, current_mood_set: Moodverse):
self.__known_moods: Moodverse = current_mood_set

def create_dated_entry_from_row(self,
line: dict[str],
override_mood_set: Moodverse = Moodverse()) -> dated_entry.DatedEntry:
line: dict[str, str]) -> dated_entry.DatedEntry:
"""
:func:`access_dated_entry` of :class:`DatedEntry` object with the specified parameters.
:raises TriedCreatingDuplicateDatedEntryError: if it would result in making a duplicate :class:`DatedEntry`
:raises IncompleteDataRow: if ``line`` does not have ``time`` and ``mood`` keys at the very least
:raises IncompleteDataRow: if ``line`` does not have ``time mood`` keys at the very least, or either is empty
:raises ValueError: re-raises ValueError from :class:`DatedEntry`
:param line: a dictionary of strings. Required keys: mood, activities, note_title & note.
:param override_mood_set: each key of the dict should have a set of strings containing moods.
"""
# TODO: test case this
# Try accessing the minimum required keys
Expand All @@ -168,6 +168,10 @@ def create_dated_entry_from_row(self,
line[key]
except KeyError:
raise IncompleteDataRow(key)
# is it empty then, maybe?
else:
if not line[key]:
raise IncompleteDataRow(key)

# Check if there's already an object with this time
if line["time"] in self.__known_entries_for_this_date:
Expand Down
2 changes: 2 additions & 0 deletions dated_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def __init__(self,
# ---
# MOOD
# ---
if len(mood) == 0:
raise ValueError
# Check if the mood is valid - i.e. it does exist in the currently used Moodverse
if not override_mood_set.get_mood(mood):
errors.ErrorMsgBase.print(ErrorMsg.INVALID_MOOD, mood)
Expand Down
2 changes: 1 addition & 1 deletion librarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def __process_line(self, line: dict[str]) -> bool:
else:
# Let DatedEntriesGroup handle the rest and increment the counter (True == 1)
try:
self.access_date(line["full_date"]).create_dated_entry_from_row(line, self.__mood_set)
self.access_date(line["full_date"]).create_dated_entry_from_row(line)
except (dated_entries_group.TriedCreatingDuplicateDatedEntryError,
dated_entries_group.IncompleteDataRow,
dated_entries_group.InvalidDateError,
Expand Down
4 changes: 3 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def expand_path(path):
# Gets full path, resolving things like ../
return os.path.realpath(
# Expands the tilde (~) character to the user's home directory
os.path.expanduser(path)
os.path.expanduser(
os.path.expandvars(path)
)
)

0 comments on commit b1e7b4f

Please sign in to comment.