Skip to content

Commit

Permalink
Finish migration to native pytest (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin authored Feb 23, 2022
1 parent 72e9714 commit e382ba9
Show file tree
Hide file tree
Showing 9 changed files with 749 additions and 844 deletions.
51 changes: 25 additions & 26 deletions benchmarks/driver/parsing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io
import json
import re
from unittest import TestCase

import pytest
import ujson
Expand All @@ -33,7 +32,7 @@
disable_gc=True,
)
def test_sort_reverse_and_regexp_small(benchmark):
benchmark(sort_parsing_candidate_reverse_and_regexp, ParsingBenchmarks.small_page)
benchmark(sort_parsing_candidate_reverse_and_regexp, TestParsingBenchmarks.small_page)


@pytest.mark.benchmark(
Expand All @@ -43,7 +42,7 @@ def test_sort_reverse_and_regexp_small(benchmark):
disable_gc=True,
)
def test_sort_reverse_and_regexp_large(benchmark):
benchmark(sort_parsing_candidate_reverse_and_regexp, ParsingBenchmarks.large_page)
benchmark(sort_parsing_candidate_reverse_and_regexp, TestParsingBenchmarks.large_page)


def sort_parsing_candidate_reverse_and_regexp(response):
Expand All @@ -61,7 +60,7 @@ def sort_parsing_candidate_reverse_and_regexp(response):
disable_gc=True,
)
def test_sort_rfind_and_regexp_small(benchmark):
benchmark(sort_parsing_candidate_rfind_and_regexp, ParsingBenchmarks.small_page)
benchmark(sort_parsing_candidate_rfind_and_regexp, TestParsingBenchmarks.small_page)


@pytest.mark.benchmark(
Expand All @@ -71,7 +70,7 @@ def test_sort_rfind_and_regexp_small(benchmark):
disable_gc=True,
)
def test_sort_rfind_and_regexp_large(benchmark):
benchmark(sort_parsing_candidate_rfind_and_regexp, ParsingBenchmarks.large_page)
benchmark(sort_parsing_candidate_rfind_and_regexp, TestParsingBenchmarks.large_page)


def sort_parsing_candidate_rfind_and_regexp(response):
Expand All @@ -89,7 +88,7 @@ def sort_parsing_candidate_rfind_and_regexp(response):
disable_gc=True,
)
def test_sort_end_anchor_regexp(benchmark):
benchmark(sort_parsing_candidate_end_anchor_regexp, ParsingBenchmarks.small_page)
benchmark(sort_parsing_candidate_end_anchor_regexp, TestParsingBenchmarks.small_page)


@pytest.mark.benchmark(
Expand All @@ -99,7 +98,7 @@ def test_sort_end_anchor_regexp(benchmark):
disable_gc=True,
)
def test_sort_end_anchor_regexp_large(benchmark):
benchmark(sort_parsing_candidate_end_anchor_regexp, ParsingBenchmarks.large_page)
benchmark(sort_parsing_candidate_end_anchor_regexp, TestParsingBenchmarks.large_page)


def sort_parsing_candidate_end_anchor_regexp(response):
Expand All @@ -118,7 +117,7 @@ def sort_parsing_candidate_end_anchor_regexp(response):
disable_gc=True,
)
def test_sort_find_all_regexp_small(benchmark):
benchmark(sort_parsing_candidate_find_all, ParsingBenchmarks.small_page)
benchmark(sort_parsing_candidate_find_all, TestParsingBenchmarks.small_page)


@pytest.mark.benchmark(
Expand All @@ -128,7 +127,7 @@ def test_sort_find_all_regexp_small(benchmark):
disable_gc=True,
)
def test_sort_find_all_regexp_large(benchmark):
benchmark(sort_parsing_candidate_find_all, ParsingBenchmarks.large_page)
benchmark(sort_parsing_candidate_find_all, TestParsingBenchmarks.large_page)


def sort_parsing_candidate_find_all(response):
Expand All @@ -144,7 +143,7 @@ def sort_parsing_candidate_find_all(response):
disable_gc=True,
)
def test_pit_id_regexp_small(benchmark):
benchmark(pit_id_parsing_candidate_regexp, ParsingBenchmarks.small_page)
benchmark(pit_id_parsing_candidate_regexp, TestParsingBenchmarks.small_page)


@pytest.mark.benchmark(
Expand All @@ -154,7 +153,7 @@ def test_pit_id_regexp_small(benchmark):
disable_gc=True,
)
def test_pit_id_regexp_large(benchmark):
benchmark(pit_id_parsing_candidate_regexp, ParsingBenchmarks.large_page)
benchmark(pit_id_parsing_candidate_regexp, TestParsingBenchmarks.large_page)


def pit_id_parsing_candidate_regexp(response):
Expand All @@ -170,7 +169,7 @@ def pit_id_parsing_candidate_regexp(response):
disable_gc=True,
)
def test_combined_json_small(benchmark):
benchmark(combined_parsing_candidate_json_loads, ParsingBenchmarks.small_page)
benchmark(combined_parsing_candidate_json_loads, TestParsingBenchmarks.small_page)


@pytest.mark.benchmark(
Expand All @@ -180,7 +179,7 @@ def test_combined_json_small(benchmark):
disable_gc=True,
)
def test_combined_json_large(benchmark):
benchmark(combined_parsing_candidate_json_loads, ParsingBenchmarks.large_page)
benchmark(combined_parsing_candidate_json_loads, TestParsingBenchmarks.large_page)


def combined_parsing_candidate_json_loads(response):
Expand All @@ -197,7 +196,7 @@ def combined_parsing_candidate_json_loads(response):
disable_gc=True,
)
def test_combined_ijson_large(benchmark):
benchmark(combined_parsing_candidate_json_loads, ParsingBenchmarks.large_page)
benchmark(combined_parsing_candidate_json_loads, TestParsingBenchmarks.large_page)


@pytest.mark.benchmark(
Expand All @@ -207,7 +206,7 @@ def test_combined_ijson_large(benchmark):
disable_gc=True,
)
def test_combined_ijson_small(benchmark):
benchmark(combined_parsing_candidate_json_loads, ParsingBenchmarks.small_page)
benchmark(combined_parsing_candidate_json_loads, TestParsingBenchmarks.small_page)


def combined_parsing_candidate_ijson_loads(response):
Expand All @@ -224,7 +223,7 @@ def combined_parsing_candidate_ijson_loads(response):
disable_gc=True,
)
def test_pit_id_parse_small(benchmark):
page = ParsingBenchmarks.small_page.encode()
page = TestParsingBenchmarks.small_page.encode()
benchmark(pit_id_parsing_candidate_runner_parse, page)


Expand All @@ -235,7 +234,7 @@ def test_pit_id_parse_small(benchmark):
disable_gc=True,
)
def test_pit_id_parse_large(benchmark):
page = ParsingBenchmarks.large_page.encode()
page = TestParsingBenchmarks.large_page.encode()
benchmark(pit_id_parsing_candidate_runner_parse, page)


Expand All @@ -246,33 +245,33 @@ def pit_id_parsing_candidate_runner_parse(response):
return pit_id


class ParsingBenchmarks(TestCase):
class TestParsingBenchmarks:
def test_all_candidates(self):
"""
Quick utility test to ensure all benchmark cases are correct
"""

pit_id = pit_id_parsing_candidate_runner_parse(self.small_page.encode())
self.assertEqual("fedcba9876543210", pit_id)
assert pit_id == "fedcba9876543210"

sort = sort_parsing_candidate_reverse_and_regexp(self.small_page)
self.assertEqual([1609780186, "2"], sort)
assert sort == [1609780186, "2"]

sort = sort_parsing_candidate_rfind_and_regexp(self.large_page)
self.assertEqual([1609780186, "2"], sort)
assert sort == [1609780186, "2"]

sort = sort_parsing_candidate_end_anchor_regexp(self.small_page)
self.assertEqual([1609780186, "2"], sort)
assert sort == [1609780186, "2"]

sort = sort_parsing_candidate_find_all(self.large_page)
self.assertEqual([1609780186, "2"], sort)
assert sort == [1609780186, "2"]

pit_id = pit_id_parsing_candidate_regexp(self.large_page)
self.assertEqual("fedcba9876543210", pit_id)
assert pit_id == "fedcba9876543210"

pit_id, sort = combined_parsing_candidate_json_loads(self.small_page)
self.assertEqual([1609780186, "2"], sort)
self.assertEqual("fedcba9876543210", pit_id)
assert sort == [1609780186, "2"]
assert pit_id == "fedcba9876543210"

small_page = """
{
Expand Down
Loading

0 comments on commit e382ba9

Please sign in to comment.