refactor(06-02): update CLI and test imports to kb_workflow.pipeline
- Remove sys.path manipulation from kb_workflow.py - Update CLI imports to use kb_workflow.pipeline prefix - Update all test file imports and patch paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ class TestLinkParserBilibiliVideo:
|
||||
|
||||
def test_parse_bilibili_video_url_returns_correct_parsed_link(self):
|
||||
"""Test 1: 解析B站视频URL返回正确的 ParsedLink (platform=bilibili, type=video, id=BVxxx)"""
|
||||
from kb_pipeline.link_parser import LinkParser, ParsedLink
|
||||
from kb_workflow.pipeline.link_parser import LinkParser, ParsedLink
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://www.bilibili.com/video/BV1GJ411x7Qw")
|
||||
@@ -31,7 +31,7 @@ class TestLinkParserBilibiliVideo:
|
||||
|
||||
def test_parse_bilibili_video_url_without_www(self):
|
||||
"""B站视频URL不带www也能正确解析"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://bilibili.com/video/BV1GJ411x7Qw")
|
||||
@@ -43,7 +43,7 @@ class TestLinkParserBilibiliVideo:
|
||||
|
||||
def test_parse_bilibili_video_url_with_http(self):
|
||||
"""B站视频URL使用http也能正确解析"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("http://www.bilibili.com/video/BV1GJ411x7Qw")
|
||||
@@ -58,7 +58,7 @@ class TestLinkParserBilibiliArticle:
|
||||
|
||||
def test_parse_bilibili_article_url_returns_correct_parsed_link(self):
|
||||
"""Test 2: 解析B站专栏URL返回正确的 ParsedLink (platform=bilibili, type=article, id=cvxxx)"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://www.bilibili.com/read/cv12345678")
|
||||
@@ -70,7 +70,7 @@ class TestLinkParserBilibiliArticle:
|
||||
|
||||
def test_parse_bilibili_article_url_with_article_prefix(self):
|
||||
"""B站专栏URL使用article前缀也能正确解析"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://www.bilibili.com/article/cv12345678")
|
||||
@@ -86,7 +86,7 @@ class TestLinkParserZhihuAnswer:
|
||||
|
||||
def test_parse_zhihu_answer_url_returns_correct_parsed_link(self):
|
||||
"""Test 3: 解析知乎问答URL返回正确的 ParsedLink (platform=zhihu, type=answer, id=xxx)"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://www.zhihu.com/question/12345678/answer/87654321")
|
||||
@@ -98,7 +98,7 @@ class TestLinkParserZhihuAnswer:
|
||||
|
||||
def test_parse_zhihu_answer_url_without_www(self):
|
||||
"""知乎问答URL不带www也能正确解析"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://zhihu.com/question/12345678/answer/87654321")
|
||||
@@ -113,7 +113,7 @@ class TestLinkParserZhihuZhuanlan:
|
||||
|
||||
def test_parse_zhihu_zhuanlan_url_returns_correct_parsed_link(self):
|
||||
"""Test 4: 解析知乎专栏URL返回正确的 ParsedLink (platform=zhihu, type=zhuanlan, id=xxx)"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://zhuanlan.zhihu.com/p/12345678")
|
||||
@@ -127,10 +127,10 @@ class TestLinkParserZhihuZhuanlan:
|
||||
class TestLinkParserShortLink:
|
||||
"""Tests for short link resolution"""
|
||||
|
||||
@patch("kb_pipeline.link_parser.requests.head")
|
||||
@patch("kb_workflow.pipeline.link_parser.requests.head")
|
||||
def test_parse_b23tv_shortlink_resolves_to_real_url(self, mock_head):
|
||||
"""Test 5: 解析b23.tv短链返回解析后的真实URL"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
# Mock the redirect response
|
||||
mock_response = MagicMock()
|
||||
@@ -147,10 +147,10 @@ class TestLinkParserShortLink:
|
||||
assert result.content_id == "BV1GJ411x7Qw"
|
||||
assert result.resolved_url == "https://www.bilibili.com/video/BV1GJ411x7Qw"
|
||||
|
||||
@patch("kb_pipeline.link_parser.requests.head")
|
||||
@patch("kb_workflow.pipeline.link_parser.requests.head")
|
||||
def test_shortlink_resolution_uses_allow_redirects(self, mock_head):
|
||||
"""短链解析应该使用 allow_redirects=True"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
@@ -170,7 +170,7 @@ class TestLinkParserUnknownURL:
|
||||
|
||||
def test_parse_unknown_url_returns_none(self):
|
||||
"""Test 6: 无法识别的URL返回None(不抛异常)"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
||||
@@ -179,7 +179,7 @@ class TestLinkParserUnknownURL:
|
||||
|
||||
def test_parse_invalid_url_returns_none(self):
|
||||
"""无效URL返回None"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("not a valid url")
|
||||
@@ -188,7 +188,7 @@ class TestLinkParserUnknownURL:
|
||||
|
||||
def test_parse_empty_string_returns_none(self):
|
||||
"""空字符串返回None"""
|
||||
from kb_pipeline.link_parser import LinkParser
|
||||
from kb_workflow.pipeline.link_parser import LinkParser
|
||||
|
||||
parser = LinkParser()
|
||||
result = parser.parse("")
|
||||
@@ -201,7 +201,7 @@ class TestParsedLink:
|
||||
|
||||
def test_parsed_link_has_all_required_fields(self):
|
||||
"""ParsedLink 应包含所有必需字段"""
|
||||
from kb_pipeline.link_parser import ParsedLink
|
||||
from kb_workflow.pipeline.link_parser import ParsedLink
|
||||
|
||||
link = ParsedLink(
|
||||
platform="bilibili",
|
||||
@@ -219,7 +219,7 @@ class TestParsedLink:
|
||||
|
||||
def test_parsed_link_resolved_url_defaults_to_original(self):
|
||||
"""ParsedLink 的 resolved_url 默认等于 original_url"""
|
||||
from kb_pipeline.link_parser import ParsedLink
|
||||
from kb_workflow.pipeline.link_parser import ParsedLink
|
||||
|
||||
link = ParsedLink(
|
||||
platform="bilibili",
|
||||
|
||||
Reference in New Issue
Block a user