Skip to content

Commit

Permalink
Even more
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTyton committed Sep 26, 2024
1 parent 314531a commit 2bc7f6f
Showing 1 changed file with 81 additions and 65 deletions.
146 changes: 81 additions & 65 deletions root/app/regex_parsing_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import unittest
from typing import NamedTuple, Optional
Expand All @@ -17,13 +18,24 @@ class CheckFilenameExtractionTestCase(NamedTuple):
@parameterized.expand(
[
# Test case: Extract 'story' from 'story-name-1234'
CheckFilenameExtractionTestCase(input="story-name-1234", expected="story"),
CheckFilenameExtractionTestCase(
input="story-name-1234", expected="story"
),
# Test case: Extract 'author' from 'author-name'
CheckFilenameExtractionTestCase(input="author-name", expected="author"),
CheckFilenameExtractionTestCase(
input="author-name", expected="author"
),
# Test case: Extract 'story' from '/path/story-name-1234.epub'
CheckFilenameExtractionTestCase(input="/path/story-name-1234.epub", expected="story"),
CheckFilenameExtractionTestCase(
input=os.path.join("path", "story-name-1234.epub"),
expected="story",
),
# Test case: Extract 'story' from '\\path\\to\\story-name-1234.epub'
CheckFilenameExtractionTestCase(input="\\path\\to\\story-name-1234.epub", expected="story"), ]
CheckFilenameExtractionTestCase(
input=os.path.join("path", "to", "story-name-1234.epub"),
expected="story",
),
]
)
def test_extract_filename(self, input, expected):
self.assertEqual(regex_parsing.extract_filename(input), expected)
Expand Down Expand Up @@ -54,7 +66,12 @@ class CheckRegexesTestCase(NamedTuple):
)
@patch("regex_parsing.ff_logging.log_failure")
def test_check_regexes(
self, test_output, test_pattern, test_message, expected_result, mock_log_failure
self,
test_output,
test_pattern,
test_message,
expected_result,
mock_log_failure,
):
self.assertEqual(
regex_parsing.check_regexes(
Expand All @@ -72,28 +89,26 @@ class CheckRegexFailuresTestCase(NamedTuple):
expected: bool
message: Optional[str]

@parameterized.expand([
# Test case: Output contains 5 chapters, expected failure, with a specific message
CheckRegexFailuresTestCase(
output="test output already contains 5 chapters.",
expected=False,
message="Issue with story, site is broken. Story likely hasn't updated on site yet."
),
# Test case: Output doesn't contain any recognizable chapters, expected failure, with a specific message
CheckRegexFailuresTestCase(
output="test output doesn't contain any recognizable chapters, probably from a different source. Not updating.",
expected=False,
message="Something is messed up with the site or the epub. No chapters found."
),
# Test case: Generic output, expected success, no specific message
CheckRegexFailuresTestCase(
output="test output",
expected=True,
message=None
),
])
@parameterized.expand(
[
# Test case: Output contains 5 chapters, expected failure, with a specific message
CheckRegexFailuresTestCase(
output="test output already contains 5 chapters.",
expected=False,
message="Issue with story, site is broken. Story likely hasn't updated on site yet.",
),
# Test case: Output doesn't contain any recognizable chapters, expected failure, with a specific message
CheckRegexFailuresTestCase(
output="test output doesn't contain any recognizable chapters, probably from a different source. Not updating.",
expected=False,
message="Something is messed up with the site or the epub. No chapters found.",
),
# Test case: Generic output, expected success, no specific message
CheckRegexFailuresTestCase(
output="test output", expected=True, message=None
),
]
)
@patch("regex_parsing.ff_logging.log_failure")
def test_check_failure_regexes(
self, input, expected, log_message, mock_log_failure
Expand All @@ -109,28 +124,26 @@ class CheckForceableRegexTestCase(NamedTuple):
expected: bool
message: Optional[str]

@parameterized.expand([
# Test case: Output contains 5 chapters, more than source: 3, expected True, with a specific message
CheckForceableRegexTestCase(
output="test output contains 5 chapters, more than source: 3.",
expected=True,
message="Chapter difference between source and destination. Forcing update."
),
# Test case: File has been updated more recently than the story, expected True, with a specific message
CheckForceableRegexTestCase(
output="File(test.epub) Updated(2022-01-01) more recently than Story(2021-12-31) - Skipping",
expected=True,
message="File has been updated more recently than the story, this is likely a metadata bug. Forcing update."
),
# Test case: Generic output, expected False, no specific message
CheckForceableRegexTestCase(
output="test output",
expected=False,
message=None
),
])
@parameterized.expand(
[
# Test case: Output contains 5 chapters, more than source: 3, expected True, with a specific message
CheckForceableRegexTestCase(
output="test output contains 5 chapters, more than source: 3.",
expected=True,
message="Chapter difference between source and destination. Forcing update.",
),
# Test case: File has been updated more recently than the story, expected True, with a specific message
CheckForceableRegexTestCase(
output="File(test.epub) Updated(2022-01-01) more recently than Story(2021-12-31) - Skipping",
expected=True,
message="File has been updated more recently than the story, this is likely a metadata bug. Forcing update.",
),
# Test case: Generic output, expected False, no specific message
CheckForceableRegexTestCase(
output="test output", expected=False, message=None
),
]
)
@patch("regex_parsing.ff_logging.log_failure")
def test_check_forceable_regexes(
self, input, expected, log_message, mock_log_failure
Expand All @@ -146,22 +159,25 @@ class CheckGenerateFanficInfoTestCase(NamedTuple):
expected_url: str
expected_site: str

@parameterized.expand([
# Test case: Fanfiction.net URL
CheckGenerateFanficInfoTestCase(
url="https://www.fanfiction.net/s/1234",
expected_url="www.fanfiction.net/s/1234",
expected_site="ffnet"
),
# Test case: Archive of Our Own URL
CheckGenerateFanficInfoTestCase(
url="https://archiveofourown.org/works/5678",
expected_url="archiveofourown.org/works/5678",
expected_site="ao3"
),
])
def test_generate_FanficInfo_from_url(self, input_url, expected_url, expected_site):
@parameterized.expand(
[
# Test case: Fanfiction.net URL
CheckGenerateFanficInfoTestCase(
url="https://www.fanfiction.net/s/1234",
expected_url="www.fanfiction.net/s/1234",
expected_site="ffnet",
),
# Test case: Archive of Our Own URL
CheckGenerateFanficInfoTestCase(
url="https://archiveofourown.org/works/5678",
expected_url="archiveofourown.org/works/5678",
expected_site="ao3",
),
]
)
def test_generate_FanficInfo_from_url(
self, input_url, expected_url, expected_site
):
fanfic = regex_parsing.generate_FanficInfo_from_url(input_url)
self.assertIsInstance(fanfic, fanfic_info.FanficInfo)
self.assertEqual(fanfic.url, expected_url)
Expand Down

0 comments on commit 2bc7f6f

Please sign in to comment.