fix(test): fix the scrapers
This commit is contained in:
parent
1b77763648
commit
fe25b00537
2 changed files with 7 additions and 6 deletions
|
|
@ -143,7 +143,7 @@ def extract_example_test_case(soup) -> tuple[str, str] | None:
|
||||||
return (input_text, output_text)
|
return (input_text, output_text)
|
||||||
|
|
||||||
|
|
||||||
def scrape(url: str) -> list[tuple[str, str]]:
|
def scrape(url: str) -> list[TestCase]:
|
||||||
try:
|
try:
|
||||||
headers = {
|
headers = {
|
||||||
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||||
|
|
@ -158,7 +158,8 @@ def scrape(url: str) -> list[tuple[str, str]]:
|
||||||
if not test_case:
|
if not test_case:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return [test_case]
|
input_text, output_text = test_case
|
||||||
|
return [TestCase(input=input_text, expected=output_text)]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error scraping CSES: {e}", file=sys.stderr)
|
print(f"Error scraping CSES: {e}", file=sys.stderr)
|
||||||
|
|
@ -228,7 +229,7 @@ def main() -> None:
|
||||||
print(json.dumps(asdict(tests_result)))
|
print(json.dumps(asdict(tests_result)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
tests: list[tuple[str, str]] = scrape(url)
|
tests: list[TestCase] = scrape(url)
|
||||||
|
|
||||||
problem_id: str = (
|
problem_id: str = (
|
||||||
problem_input if problem_input.isdigit() else problem_input.split("/")[-1]
|
problem_input if problem_input.isdigit() else problem_input.split("/")[-1]
|
||||||
|
|
@ -268,7 +269,7 @@ def main() -> None:
|
||||||
print(json.dumps(asdict(tests_result)))
|
print(json.dumps(asdict(tests_result)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
test_cases = [TestCase(input=i, expected=o) for i, o in tests]
|
test_cases = tests
|
||||||
tests_result = TestsResult(
|
tests_result = TestsResult(
|
||||||
success=True,
|
success=True,
|
||||||
error="",
|
error="",
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ def test_scrape_success(mocker, mock_cses_html):
|
||||||
result = scrape("https://cses.fi/problemset/task/1068")
|
result = scrape("https://cses.fi/problemset/task/1068")
|
||||||
|
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0][0] == "3\n1 2 3"
|
assert result[0].input == "3\n1 2 3"
|
||||||
assert result[0][1] == "6"
|
assert result[0].expected == "6"
|
||||||
|
|
||||||
|
|
||||||
def test_scrape_all_problems(mocker):
|
def test_scrape_all_problems(mocker):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue