Browse Source

Py3: Test and code-format Sample-PostProc

pull/1253/head
Safihre 6 years ago
parent
commit
e5553e254b
  1. 7
      .travis.yml
  2. 29
      scripts/Sample-PostProc.py
  3. 40
      tests/test_functional_misc.py

7
.travis.yml

@ -45,10 +45,9 @@ script:
- python3 -m pytest -v
# Force code-style for folders that we already did, only on 1 job
- if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black tests -l120 --py36 -N --check; fi
- if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black tools -l120 --py36 -N --check; fi
- if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black util -l120 --py36 -N --check; fi
- if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then python3 -m black sabnzbd/utils -l120 --py36 -N --check; fi
- if [[ $TRAVIS_PYTHON_VERSION == "3.7" ]]; then
python3 -m black scripts tools tests util sabnzbd/utils -l120 --py36 -N --check;
fi
notifications:
email:

29
scripts/Sample-PostProc.py

@ -1,5 +1,5 @@
#!/usr/bin/env python
# Example Post-Processing Script for SABnzbd (2.3.1 and higher), written in Python.
# Example Post-Processing Script for SABnzbd (3.0.0 and higher), written in Python.
# For Linux, MacOS, Windows and any other platform with Python
# See https://sabnzbd.org/wiki/scripts/post-processing-scripts for details
#
@ -10,35 +10,34 @@ import sys, os
# Raw parsing of input parameters en SABnzbd environment variables
counter = 0
print("\nINPUT from argv:\n")
print("INPUT from argv:")
for item in sys.argv:
print("Argument", counter, ":", item)
counter += 1
print("\nINPUT from environment variables (only SAB specifics):\n")
print("INPUT from environment variables (only SAB specifics):")
for item in os.environ:
if item.find("SAB_") == 0:
if item.find("SAB_") == 0:
print(item, os.environ[item])
# More intelligent parsing:
try:
(scriptname,directory,orgnzbname,jobname,reportnumber,category,group,postprocstatus,url) = sys.argv
(scriptname, directory, orgnzbname, jobname, reportnumber, category, group, postprocstatus, url) = sys.argv
except:
print("No SAB compliant number of commandline parameters found (should be 8):", len(sys.argv)-1)
sys.exit(1) # non-zero return code
print("No SAB compliant number of commandline parameters found (should be 8):", len(sys.argv) - 1)
sys.exit(1) # non-zero return code
# Some examples:
print("\nExamples of some specific values:\n")
print("jobname is", jobname)
print("Examples of some specific values:")
print("jobname is:", jobname)
try:
sabversion = os.environ['SAB_VERSION']
print("sabversion is", sabversion)
sabversion = os.environ["SAB_VERSION"]
print("SAB_VERSION is:", sabversion)
except:
pass
''' your code here '''
""" your code here """
# We're done:
print("\nScript done. All OK.") # the last line will appear in the SABnzb History GUI
sys.exit(0) # The result code towards SABnzbd
print("Script done. All OK.") # the last line will appear in the SABnzb History GUI
sys.exit(0) # The result code towards SABnzbd

40
tests/test_functional_misc.py

@ -18,12 +18,17 @@
"""
tests.test_functional_misc - Functional tests of various functions
"""
import os
import sys
import subprocess
import sabnzbd.encoding
from tests.testhelper import *
class SABnzbdShowLoggingTest(SABnzbdBaseTest):
def test_showlog(self):
""" Test the output of the filtered-log button """
# Basic URL-fetching, easier than Selenium file download
log_result = get_url_result("status/showlog")
@ -34,3 +39,38 @@ class SABnzbdShowLoggingTest(SABnzbdBaseTest):
# Make sure sabnzbd.ini was appended
assert "__encoding__ = utf-8" in log_result
assert "[misc]" in log_result
class TestSamplePostProc:
def test_sample_post_proc(self):
""" Make sure we don't break things """
# Set parameters
script_params = [
"somedir222",
"nzbname",
"frènch_german_demö",
"Index12",
"Cat88",
"MyGroup",
"PP0",
"https://example.com/",
]
script_call = [sys.executable, "scripts/Sample-PostProc.py", "server"]
script_call.extend(script_params)
# Set parameters via env
env = os.environ.copy()
env["SAB_VERSION"] = "frènch_german_demö_version"
# Run script and check output
script_call = subprocess.Popen(script_call, stdout=subprocess.PIPE, env=env)
script_output, errs = script_call.communicate(timeout=15)
# This is a bit bad, since we use our own function
# But in a way it is also a test if the function does its job!
script_output = sabnzbd.encoding.platform_btou(script_output)
# Check if all parameters are there
for param in script_params:
assert param in script_output
assert env["SAB_VERSION"] in script_output

Loading…
Cancel
Save