fix entry unit tests
This commit is contained in:
parent
f080554ff6
commit
b63ee65396
6 changed files with 47 additions and 41 deletions
|
|
@ -268,8 +268,8 @@ class MultiUrlValidator(OptionsValidator):
|
||||||
for idx, url_validator in enumerate(self.urls.list)
|
for idx, url_validator in enumerate(self.urls.list)
|
||||||
}
|
}
|
||||||
output = script.resolve_once(url_variables)
|
output = script.resolve_once(url_variables)
|
||||||
for out in output:
|
for out in output.values():
|
||||||
has_non_empty_url |= bool(str(out))
|
has_non_empty_url |= bool(str(out))
|
||||||
|
|
||||||
if not has_non_empty_url:
|
if not output or not has_non_empty_url:
|
||||||
raise self._validation_exception("Must contain at least one url that is non-empty")
|
raise self._validation_exception("Must contain at least one url that is non-empty")
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ class Entry(BaseEntry, Scriptable):
|
||||||
def get(self, variable: Variable) -> str:
|
def get(self, variable: Variable) -> str:
|
||||||
return self.script.resolve(unresolvable=self.unresolvable).get_str(variable.variable_name)
|
return self.script.resolve(unresolvable=self.unresolvable).get_str(variable.variable_name)
|
||||||
|
|
||||||
|
def get_int(self, variable: Variable) -> int:
|
||||||
|
return self.script.resolve(unresolvable=self.unresolvable).get_int(variable.variable_name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ext(self) -> str:
|
def ext(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,8 @@ class ScriptOutput:
|
||||||
|
|
||||||
def get_str(self, name: str) -> str:
|
def get_str(self, name: str) -> str:
|
||||||
return str(self.output[name])
|
return str(self.output[name])
|
||||||
|
|
||||||
|
def get_int(self, name: str) -> int:
|
||||||
|
out = self.get_native(name)
|
||||||
|
assert isinstance(out, int)
|
||||||
|
return out
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ def mock_entry_to_dict(
|
||||||
"channel_sanitized": "abc123",
|
"channel_sanitized": "abc123",
|
||||||
"channel_id": uid,
|
"channel_id": uid,
|
||||||
"extractor": extractor,
|
"extractor": extractor,
|
||||||
|
"extractor_key": "test_extractor_key",
|
||||||
"uploader": "abc123",
|
"uploader": "abc123",
|
||||||
"uploader_id": "abc123",
|
"uploader_id": "abc123",
|
||||||
"uploader_url": "https://yourname.here",
|
"uploader_url": "https://yourname.here",
|
||||||
|
|
@ -162,8 +163,8 @@ def mock_entry_kwargs(
|
||||||
return {
|
return {
|
||||||
"id": uid,
|
"id": uid,
|
||||||
"epoch": 1596878400,
|
"epoch": 1596878400,
|
||||||
"ie_key": "test_ie_key",
|
|
||||||
"extractor": extractor,
|
"extractor": extractor,
|
||||||
|
"extractor_key": "test_extractor_key",
|
||||||
"title": title,
|
"title": title,
|
||||||
"ext": ext,
|
"ext": ext,
|
||||||
"upload_date": upload_date,
|
"upload_date": upload_date,
|
||||||
|
|
@ -174,20 +175,6 @@ def mock_entry_kwargs(
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_entry(mock_entry_kwargs):
|
def mock_entry(mock_entry_kwargs):
|
||||||
return Entry(entry_dict=mock_entry_kwargs, working_directory=".")
|
return Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script(
|
||||||
|
override_variables={}
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def validate_entry_dict_contains_valid_formatters():
|
|
||||||
def _validate_entry_dict_contains_valid_formatters(entry: Entry):
|
|
||||||
for key, value in entry.to_dict().items():
|
|
||||||
expected_string = f"test {value} formatting works"
|
|
||||||
formatter = StringFormatterValidator(
|
|
||||||
name="test", value=f"test {{{key}}} formatting works"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert formatter.apply_formatter(entry.to_dict()) == expected_string
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
return _validate_entry_dict_contains_valid_formatters
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from ytdl_sub.entries.entry import Entry
|
||||||
|
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
|
||||||
|
|
||||||
|
|
||||||
class TestEntry(object):
|
class TestEntry(object):
|
||||||
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
||||||
assert mock_entry.to_dict() == mock_entry_to_dict
|
out = mock_entry.to_dict()
|
||||||
|
del out["entry_metadata"]
|
||||||
def test_entry_dict_contains_valid_formatters(
|
assert out == mock_entry_to_dict
|
||||||
self, mock_entry, validate_entry_dict_contains_valid_formatters
|
|
||||||
):
|
|
||||||
assert validate_entry_dict_contains_valid_formatters(mock_entry)
|
|
||||||
|
|
||||||
def test_entry_missing_kwarg(self, mock_entry):
|
def test_entry_missing_kwarg(self, mock_entry):
|
||||||
key = "dne"
|
key = "dne"
|
||||||
|
|
@ -26,16 +26,25 @@ class TestEntry(object):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_entry_reverse_variables(
|
def test_entry_reverse_variables(
|
||||||
self, mock_entry, upload_date, year_rev, month_rev, day_rev, month_rev_pad, day_rev_pad
|
self,
|
||||||
|
mock_entry_kwargs,
|
||||||
|
upload_date,
|
||||||
|
year_rev,
|
||||||
|
month_rev,
|
||||||
|
day_rev,
|
||||||
|
month_rev_pad,
|
||||||
|
day_rev_pad,
|
||||||
):
|
):
|
||||||
mock_entry._kwargs["upload_date"] = upload_date
|
|
||||||
|
|
||||||
assert mock_entry.upload_year_truncated_reversed == year_rev
|
mock_entry_kwargs["upload_date"] = upload_date
|
||||||
assert mock_entry.upload_month_reversed == month_rev
|
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script(
|
||||||
assert mock_entry.upload_day_reversed == day_rev
|
override_variables={}
|
||||||
|
)
|
||||||
assert mock_entry.upload_month_reversed_padded == month_rev_pad
|
assert entry.get_int(v.upload_year_truncated_reversed) == year_rev
|
||||||
assert mock_entry.upload_day_reversed_padded == day_rev_pad
|
assert entry.get_int(v.upload_month_reversed) == month_rev
|
||||||
|
assert entry.get_int(v.upload_day_reversed) == day_rev
|
||||||
|
assert entry.get(v.upload_month_reversed_padded) == month_rev_pad
|
||||||
|
assert entry.get(v.upload_day_reversed_padded) == day_rev_pad
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"upload_date, day_year, day_year_rev, day_year_pad, day_year_rev_pad",
|
"upload_date, day_year, day_year_rev, day_year_pad, day_year_rev_pad",
|
||||||
|
|
@ -45,11 +54,14 @@ class TestEntry(object):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_entry_upload_day_of_year_variables(
|
def test_entry_upload_day_of_year_variables(
|
||||||
self, mock_entry, upload_date, day_year, day_year_rev, day_year_pad, day_year_rev_pad
|
self, mock_entry_kwargs, upload_date, day_year, day_year_rev, day_year_pad, day_year_rev_pad
|
||||||
):
|
):
|
||||||
mock_entry._kwargs["upload_date"] = upload_date
|
mock_entry_kwargs["upload_date"] = upload_date
|
||||||
|
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script(
|
||||||
|
override_variables={}
|
||||||
|
)
|
||||||
|
|
||||||
assert mock_entry.upload_day_of_year == day_year
|
assert entry.get_int(v.upload_day_of_year) == day_year
|
||||||
assert mock_entry.upload_day_of_year_reversed == day_year_rev
|
assert entry.get_int(v.upload_day_of_year_reversed) == day_year_rev
|
||||||
assert mock_entry.upload_day_of_year_padded == day_year_pad
|
assert entry.get(v.upload_day_of_year_padded) == day_year_pad
|
||||||
assert mock_entry.upload_day_of_year_reversed_padded == day_year_rev_pad
|
assert entry.get(v.upload_day_of_year_reversed_padded) == day_year_rev_pad
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,4 @@ class TestEntry(object):
|
||||||
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
|
||||||
output = mock_entry.script.resolve().as_native()
|
output = mock_entry.script.resolve().as_native()
|
||||||
del output[VARIABLES.entry_metadata.variable_name]
|
del output[VARIABLES.entry_metadata.variable_name]
|
||||||
del output[VARIABLES.extractor_key.variable_name]
|
|
||||||
assert output == mock_entry_to_dict
|
assert output == mock_entry_to_dict
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue