tests: centralize script path setup in conftest.py
Add a pytest-discovered tests/conftest.py for the last30days scripts path and remove duplicate per-file sys.path.insert boilerplate from tests. Normalize affected imports to rely on the shared scripts path and remove the now-unneeded E402 suppressions.
This commit is contained in:
+5
-10
@@ -1,20 +1,16 @@
|
||||
"""Tests for xurl_x module."""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "skills" / "last30days" / "scripts"))
|
||||
|
||||
from lib import xurl_x
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _make_api_response(tweets=None, users=None):
|
||||
"""Build a minimal X API v2 search/recent response."""
|
||||
tweets = tweets or []
|
||||
@@ -24,11 +20,11 @@ def _make_api_response(tweets=None, users=None):
|
||||
resp["includes"] = {"users": users}
|
||||
return resp
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# is_available
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestIsAvailable(unittest.TestCase):
|
||||
def test_returns_true_when_xurl_authenticated(self):
|
||||
completed = mock.Mock(returncode=0, stdout='{"username": "testuser"}')
|
||||
@@ -62,11 +58,11 @@ class TestIsAvailable(unittest.TestCase):
|
||||
with mock.patch("subprocess.run", return_value=completed):
|
||||
self.assertFalse(xurl_x.is_available())
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# search_x
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestSearchX(unittest.TestCase):
|
||||
def test_returns_parsed_json_on_success(self):
|
||||
payload = {"data": [{"id": "1", "text": "hello world", "author_id": "u1"}]}
|
||||
@@ -127,11 +123,11 @@ class TestSearchX(unittest.TestCase):
|
||||
n_idx = call_args.index("-n")
|
||||
self.assertEqual(int(call_args[n_idx + 1]), xurl_x.DEPTH_CONFIG["default"])
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# parse_x_response
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestParseXResponse(unittest.TestCase):
|
||||
def _tweet(self, id_, text, author_id, created_at=None, metrics=None):
|
||||
t = {"id": id_, "text": text, "author_id": author_id}
|
||||
@@ -240,11 +236,11 @@ class TestParseXResponse(unittest.TestCase):
|
||||
items = xurl_x.parse_x_response(resp)
|
||||
self.assertEqual(items[0]["why_relevant"], "")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# DEPTH_CONFIG
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestDepthConfig(unittest.TestCase):
|
||||
def test_all_standard_depths_present(self):
|
||||
for depth in ("quick", "default", "deep"):
|
||||
@@ -256,6 +252,5 @@ class TestDepthConfig(unittest.TestCase):
|
||||
xurl_x.DEPTH_CONFIG["quick"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user