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

Integrate CI/CD Tests for Regex and example Roku test into dev Branch #51

Merged
merged 1 commit into from
May 9, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Tests

on:
push:
branches: [dev]
pull_request:
branches: [dev]

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run regex tests
run: python ./tests/regex.py

# Add more test jobs for other types of tests
# - name: Run other tests
# run: python ./tests/other_tests.py
54 changes: 54 additions & 0 deletions tests/extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import json

def get_custom_format(format_name, arr_type, debug_level=0):
# Convert the format_name to lowercase for case-insensitive comparison
format_name = format_name.lower()

# Determine the file path based on arr_type
if arr_type.lower() == "sonarr":
file_path = 'imports/custom_formats/sonarr/custom formats (sonarr - master).json'
elif arr_type.lower() == "radarr":
file_path = 'imports/custom_formats/radarr/custom formats (radarr - master).json'
else:
raise ValueError("Unsupported arr type: choose 'sonarr' or 'radarr'")

try:
with open(file_path, 'r') as f:
custom_formats = json.load(f)
# Search for the custom format by name, case-insensitively
for custom_format in custom_formats:
if custom_format['name'].lower() == format_name:
# Debugging output if level is set to 1
if debug_level > 1:
print("Found custom format:", json.dumps(custom_format, indent=4))
return custom_format
if debug_level > 1:
print(f"{format_name} not found in {arr_type}!")
except FileNotFoundError:
if debug_level > 1:
print(f"Warning: File {file_path} not found.")
return None

# Return None if the format is not found
return None

def get_regex(custom_format, specification_name, debug_level=0):
if not custom_format:
if debug_level > 1:
print("Custom format not found.")
return "Custom format not found."
# Convert the specification_name to lowercase for case-insensitive comparison
specification_name = specification_name.lower()

for spec in custom_format.get("specifications", []):
if spec.get("name").lower() == specification_name:
for field in spec.get("fields", []):
if field.get("name").lower() == "value":
if debug_level > 1:
print(f"Found value for specification '{specification_name}': {field.get('value')}")
return field.get("value")
if debug_level > 1:
print(f"Specification '{specification_name}' found, but 'value' field not found.")
if debug_level > 1:
print(f"Specification '{specification_name}' not found.")
return "Specification or value field not found."
39 changes: 39 additions & 0 deletions tests/regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# run_tests.py
import sys
from roku import roku
# ... import other test functions

def run_tests():
tests = [
("ROKU", roku),
# ... add other test functions
]

failed_tests = []
for test_name, test_func in tests:
print(f"Running test: {test_name}")
test_result, failed_good_matches, failed_bad_matches = test_func(debug_level=0)
if test_result:
print(f"Test passed: {test_name}\n")
else:
print(f"Test failed: {test_name}")
if failed_bad_matches:
print("The following terms should not have matched:")
for platform, term in failed_bad_matches:
print(f"- {platform}: {term}")
if failed_good_matches:
print("The following terms should have matched:")
for platform, term in failed_good_matches:
print(f"- {platform}: {term}")
print()
failed_tests.append((test_name, failed_good_matches, failed_bad_matches))

if failed_tests:
print("Some tests failed!")
sys.exit(1)
else:
print("All tests passed!")
sys.exit(0)

if __name__ == "__main__":
run_tests()
77 changes: 77 additions & 0 deletions tests/roku.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from extract import get_custom_format, get_regex
import re
import sys

def roku(debug_level=0):
# Get the custom formats for "roku" from both Radarr and Sonarr
roku_radarr = get_custom_format("roku", "radarr", debug_level)
roku_sonarr = get_custom_format("roku", "sonarr", debug_level)

# Extract the regex values for both Radarr and Sonarr using get_regex
roku_value_radarr = get_regex(roku_radarr, "roku", debug_level)
roku_value_sonarr = get_regex(roku_sonarr, "roku", debug_level)

radarr_good_matches = [
"Weird The Al Yankovic Story 2022 1080p ROKU WEB-DL DD5.1 H.264-SMURF",
"The.Spiderwick.Chronicles.2024.S01E06.1028.Teeth.1080p.ROKU.WEB-DL.DD5.1.H.264-playWEB",
"The Imitation Game 2014 1080p ROKU WEB-DL AAC 2 0 H 264-PiRaTeS"
]
radarr_bad_matches = [
"Ikimono no kiroku 1955 720p BluRay FLAC x264-EA.mkv"
]
sonarr_good_matches = [
"The Now S01 1080p ROKU WEB-DL DD5 1 H 264-WELP",
"The Rockford Files S01 1080p ROKU WEB-DL HE-AAC 2 0 H 264-PiRaTeS",
"50.States.of.Fright.S02E05.13.Steps.to.Hell.Washington.Part.2.1080p.ROKU.WEB-DL.DD5.1.H.264-NTb"
]
sonarr_bad_matches = [
"Avatar.The.Last.Airbender.S01E08.Avatar.Roku.Winter.Solstice.2.1080p.AMZN.WEB-DL.DD+2.0.H.264-CtrlHD",
"[HorribleSubs] Rokujouma no Shinryakusha - 01 [480p]"
]


failed_good_matches = []
failed_bad_matches = []

# Check Radarr good matches
for term in radarr_good_matches:
if not re.search(roku_value_radarr, term, re.IGNORECASE):
failed_good_matches.append(("Radarr", term))

# Check Radarr bad matches
for term in radarr_bad_matches:
if re.search(roku_value_radarr, term, re.IGNORECASE):
failed_bad_matches.append(("Radarr", term))

# Check Sonarr good matches
for term in sonarr_good_matches:
if not re.search(roku_value_sonarr, term, re.IGNORECASE):
failed_good_matches.append(("Sonarr", term))

# Check Sonarr bad matches
for term in sonarr_bad_matches:
if re.search(roku_value_sonarr, term, re.IGNORECASE):
failed_bad_matches.append(("Sonarr", term))

# Return test result as a tuple (status, failed_good_matches, failed_bad_matches)
if not failed_good_matches and not failed_bad_matches:
if debug_level > 0:
print("Test Passed!")
return True, [], []
else:
return False, failed_good_matches, failed_bad_matches

# Call the test function with debug level
if __name__ == "__main__":
test_result, failed_good_matches, failed_bad_matches = roku(1)
if not test_result:
print("Test Failed!")
if failed_bad_matches:
print("\nThe following terms should not have matched:")
for platform, term in failed_bad_matches:
print(f"- {platform}: {term}")
if failed_good_matches:
print("\nThe following terms should have matched:")
for platform, term in failed_good_matches:
print(f"- {platform}: {term}")
sys.exit(1)
Loading