repo_id
stringclasses
409 values
prefix
large_stringlengths
34
36.3k
target
large_stringlengths
1
498
assertion_type
stringclasses
31 values
difficulty
stringclasses
8 values
test_file
stringlengths
10
121
test_function
stringlengths
1
104
test_class
stringlengths
0
51
lineno
int32
2
11.3k
commit_idx
int32
Mayitzin/ahrs
import unittest import numpy as np import ahrs GENERATOR = np.random.default_rng(42) THRESHOLD = 1e-6 SQRT2_2 = np.sqrt(2)/2 class TestDCM(unittest.TestCase): def setUp(self) -> None: self.R0 = ahrs.DCM() self.vector = GENERATOR.random(3)*180-90 self.R = ahrs.DCM(rpy=self.vector) s...
rmy45)
assert_*
variable
tests/test_dcm.py
test_rotation_matrix_from_euler_angles
TestDCM
39
null
Mayitzin/ahrs
import unittest import numpy as np import ahrs.utils.core as ahrs_core class TestCoreFunctions(unittest.TestCase): def test_assert_same_shapes(self): self.assertRaises(
ValueError)
self.assertRaises
variable
tests/test_core_functions.py
test_assert_same_shapes
TestCoreFunctions
8
null
Mayitzin/ahrs
import unittest import numpy as np import ahrs GENERATOR = np.random.default_rng(42) THRESHOLD = 1e-6 SQRT2_2 = np.sqrt(2)/2 class TestDCM(unittest.TestCase): def setUp(self) -> None: self.R0 = ahrs.DCM() self.vector = GENERATOR.random(3)*180-90 self.R = ahrs.DCM(rpy=self.vector) s...
rmx45)
assert_*
variable
tests/test_dcm.py
test_rotation_matrix_from_euler_angles
TestDCM
38
null
Mayitzin/ahrs
import os import unittest import numpy as np import ahrs class TestWMM(unittest.TestCase): def _load_test_values(self, filename: str) -> np.ndarray: """ Load test values from file. Parameters ---------- filename : str Path to file with test values. Ret...
f"Expected {test_values['D'][i]:.2f}, result {self.wmm.D:.2f}")
self.assertAlmostEqual
string_literal
tests/test_wmm.py
test_wmm2015
TestWMM
88
null
Mayitzin/ahrs
import unittest import numpy as np import ahrs.utils.core as ahrs_core class TestCoreFunctions(unittest.TestCase): def test_get_nan_intervals(self): A = np.random.random((10, 3)) A[[1, 3, 4, 5, 8, 9]] = np.nan self.assertEqual(ahrs_core.get_nan_intervals(A),
[(1, 1), (3, 5), (8, 9)])
self.assertEqual
collection
tests/test_core_functions.py
test_get_nan_intervals
TestCoreFunctions
19
null
Mayitzin/ahrs
import os import unittest import numpy as np import ahrs class TestWMM(unittest.TestCase): def _load_test_values(self, filename: str) -> np.ndarray: """ Load test values from file. Parameters ---------- filename : str Path to file with test values. Ret...
f"Expected {test_values['Z'][i]:.1f}, result {self.wmm.Z:.1f}")
self.assertAlmostEqual
string_literal
tests/test_wmm.py
test_wmm2015
TestWMM
86
null
Mayitzin/ahrs
import unittest import numpy as np import ahrs SQ22 = np.sqrt(2)/2 COS_SQ22 = np.cos(SQ22) SIN_SQ22 = np.sin(SQ22) EXP_SQ22 = np.exp(SQ22) class TestQuaternion(unittest.TestCase): def setUp(self) -> None: # Identity Quaternion self.q0 = ahrs.Quaternion() # Versor from 3D array self...
TypeError)
self.assertRaises
variable
tests/test_quaternions.py
test_wrong_input_array
TestQuaternion
108
null
Mayitzin/ahrs
import unittest import numpy as np import ahrs THRESHOLD = 0.5 SENSOR_DATA = ahrs.Sensors(num_samples=1000, in_degrees=False) REFERENCE_QUATERNIONS = SENSOR_DATA.quaternions REFERENCE_ROTATIONS = SENSOR_DATA.rotations class TestTRIAD(unittest.TestCase): def setUp(self) -> None: self.accelerometers = np.c...
THRESHOLD)
self.assertLess
variable
tests/test_estimators.py
test_multiple_values
TestTRIAD
21
null
Mayitzin/ahrs
import os import unittest import numpy as np import ahrs class TestWMM(unittest.TestCase): def _load_test_values(self, filename: str) -> np.ndarray: """ Load test values from file. Parameters ---------- filename : str Path to file with test values. Ret...
f"Expected {test_values['I'][i]:.2f}, result {self.wmm.I:.2f}")
self.assertAlmostEqual
string_literal
tests/test_wmm.py
test_wmm2015
TestWMM
87
null
Mayitzin/ahrs
import unittest import ahrs class TestWELMEC(unittest.TestCase): def test_correct_values(self): self.assertAlmostEqual(ahrs.utils.welmec_gravity(52.3, 80.0), 9.812484, places=6) # Braunschweig, Germany self.assertAlmostEqual(ahrs.utils.welmec_gravity(60.0, 250.0),
9.818399)
self.assertAlmostEqual
numeric_literal
tests/test_wgs84.py
test_correct_values
TestWELMEC
8
null
Mayitzin/ahrs
import unittest import ahrs class TestWGS84(unittest.TestCase): def setUp(self) -> None: self.wgs = ahrs.utils.WGS() def test_values(self): self.assertAlmostEqual(self.wgs.a, 6_378_137.0, 1) self.assertAlmostEqual(self.wgs.f, 1/298.257223563, 7) self.assertAlmostEqual(self.wgs....
4)
self.assertAlmostEqual
numeric_literal
tests/test_wgs84.py
test_values
TestWGS84
31
null
Mayitzin/ahrs
import unittest import numpy as np import ahrs THRESHOLD = 0.5 SENSOR_DATA = ahrs.Sensors(num_samples=1000, in_degrees=False) REFERENCE_QUATERNIONS = SENSOR_DATA.quaternions REFERENCE_ROTATIONS = SENSOR_DATA.rotations class TestAQUA(unittest.TestCase): def setUp(self) -> None: self.gyroscopes = np.copy(S...
1.0)
self.assertEqual
numeric_literal
tests/test_estimators.py
test_adaptive_gain
TestAQUA
358
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestTocDataClass: def test_nested_children(self): """测试嵌套的子节点结构""" c...
1
assert
numeric_literal
tests/test_toc.py
test_nested_children
TestTocDataClass
280
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestReadTocEpub: def test_read_little_prince_toc(self, toc_temp_dir): """测试读...
0
assert
numeric_literal
tests/test_toc.py
test_read_little_prince_toc
TestReadTocEpub
33
null
oomol-lab/epub-translator
import io import unittest from typing import cast from xml.etree.ElementTree import Element from epub_translator.xml.xml_like import XMLLikeNode class TestXMLLikeNode(unittest.TestCase): def test_preserve_encoding_utf8(self): """测试保留 UTF-8 编码""" original_content = b"""<?xml version="1.0" encoding...
result)
self.assertIn
variable
tests/test_xml_like.py
test_preserve_encoding_utf8
TestXMLLikeNode
34
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement from epub_translator.xml import decode_friendly, encode_friendly class TestFriendlyXML(unittest.TestCase): def test_decode_malformed_tags(self): """测试解码不匹配的标签""" # 缺少闭合标签的情况 xml_str = "<p>Unclosed tag" elements ...
0)
self.assertGreaterEqual
numeric_literal
tests/test_xml_friendly.py
test_decode_malformed_tags
TestFriendlyXML
94
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestWriteMetadata: def test_translate_metadata_fi...
"小王子"
assert
string_literal
tests/test_metadata.py
test_translate_metadata_fields
TestWriteMetadata
140
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestReadMetadata: def test_read_little_prince_met...
6
assert
numeric_literal
tests/test_metadata.py
test_read_little_prince_metadata
TestReadMetadata
25
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestMetadataFieldDataClass: def test_create_metad...
"title"
assert
string_literal
tests/test_metadata.py
test_create_metadata_field
TestMetadataFieldDataClass
188
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement from epub_translator.xml import decode_friendly, encode_friendly class TestFriendlyXML(unittest.TestCase): def test_decode_nested_tags(self): """测试解码嵌套标签""" xml_str = "<div><p>First</p><p>Second</p></div>" elements = li...
2)
self.assertEqual
numeric_literal
tests/test_xml_friendly.py
test_decode_nested_tags
TestFriendlyXML
42
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import fromstring, tostring from epub_translator.segment.inline_segment import ( InlineSegment, InlineUnexpectedIDError, InlineWrongTagCountError, search_inline_segments, ) from epub_translator.segment.text_segment import search_text_segments from epub_transla...
em)
self.assertIsNotNone
variable
tests/test_inline_segment.py
test_create_nested_structure
TestCreateElement
155
null
oomol-lab/epub-translator
import unittest from epub_translator.xml.self_closing import self_close_void_elements, unclose_void_elements class TestUncloseVoidElements(unittest.TestCase): def test_roundtrip_consistency(self): """测试往返转换的一致性""" # 对于 text/html,应该能够先 self_close 再 unclose,回到类似的形式 original = '<br><meta cha...
unclosed)
self.assertIn
variable
tests/test_self_closing.py
test_roundtrip_consistency
TestUncloseVoidElements
318
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement, fromstring, tostring from epub_translator.segment.text_segment import combine_text_segments, search_text_segments class TestEdgeCases(unittest.TestCase): def test_empty_root(self): """测试空根元素""" root = Element("p") seg...
0)
self.assertEqual
numeric_literal
tests/test_text_segment.py
test_empty_root
TestEdgeCases
315
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, fromstring, tostring from epub_translator.segment import search_text_segments from epub_translator.utils import normalize_whitespace from epub_translator.xml import iter_with_stack from epub_translator.xml_translator.stream_mapper import InlineSegmentMapping f...
result)
self.assertIsNotNone
variable
tests/test_submitter.py
test_bug_indirect_child_in_platform_structure
TestBugReproduction
360
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestReadTocEpub: def test_read_little_prince_toc(self, toc_temp_dir): """测试读...
"0"
assert
string_literal
tests/test_toc.py
test_read_little_prince_toc
TestReadTocEpub
31
null
oomol-lab/epub-translator
from xml.etree import ElementTree as ET from epub_translator.epub.metadata import MetadataField from epub_translator.epub.toc import Toc from epub_translator.translation.epub_transcode import ( decode_metadata, decode_toc, decode_toc_list, encode_metadata, encode_toc, encode_toc_list, ) class ...
3
assert
numeric_literal
tests/test_epub_transcode.py
test_encode_multiple_same_tag
TestEncodeMetadata
335
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement, fromstring, tostring from epub_translator.segment.text_segment import combine_text_segments, search_text_segments class TestSearchTextSegments(unittest.TestCase): def test_search_multiple_siblings(self): """测试提取兄弟元素""" root = ...
2)
self.assertEqual
numeric_literal
tests/test_text_segment.py
test_search_multiple_siblings
TestSearchTextSegments
56
null
oomol-lab/epub-translator
import io import unittest from typing import cast from xml.etree.ElementTree import Element from epub_translator.xml.xml_like import XMLLikeNode class TestXMLLikeNode(unittest.TestCase): def test_clean_namespaces(self): """测试清理命名空间""" original_content = b"""<?xml version="1.0"?> <html xmlns="http...
elem.tag)
self.assertNotIn
complex_expr
tests/test_xml_like.py
test_clean_namespaces
TestXMLLikeNode
69
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, fromstring, tostring from epub_translator.segment import search_text_segments from epub_translator.utils import normalize_whitespace from epub_translator.xml import iter_with_stack from epub_translator.xml_translator.stream_mapper import InlineSegmentMapping f...
normalize_whitespace(expected).strip())
self.assertEqual
func_call
tests/test_submitter.py
test_replace_peak_simple
TestSubmitReplace
58
null
oomol-lab/epub-translator
from xml.etree import ElementTree as ET from epub_translator.epub.metadata import MetadataField from epub_translator.epub.toc import Toc from epub_translator.translation.epub_transcode import ( decode_metadata, decode_toc, decode_toc_list, encode_metadata, encode_toc, encode_toc_list, ) class ...
None
assert
none_literal
tests/test_epub_transcode.py
test_encode_simple_toc
TestEncodeToc
35
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import fromstring, tostring from epub_translator.segment.inline_segment import ( InlineSegment, InlineUnexpectedIDError, InlineWrongTagCountError, search_inline_segments, ) from epub_translator.segment.text_segment import search_text_segments from epub_transla...
0)
self.assertEqual
numeric_literal
tests/test_inline_segment.py
test_validate_correct_structure
TestValidate
175
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.spines import search_spine_paths from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture spines_temp_dir = create_temp_dir_fixture("spines") class TestSearchSpinePathsEpub2: def test_search_little_prince_spines(self, spines_temp...
28
assert
numeric_literal
tests/test_spines.py
test_search_little_prince_spines
TestSearchSpinePathsEpub2
26
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestWriteMetadata: def test_translate_metadata_fi...
"小说"
assert
string_literal
tests/test_metadata.py
test_translate_metadata_fields
TestWriteMetadata
143
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestReadMetadata: def test_read_little_prince_met...
tag_names
assert
variable
tests/test_metadata.py
test_read_little_prince_metadata
TestReadMetadata
29
null
oomol-lab/epub-translator
from xml.etree import ElementTree as ET from epub_translator.epub.metadata import MetadataField from epub_translator.epub.toc import Toc from epub_translator.translation.epub_transcode import ( decode_metadata, decode_toc, decode_toc_list, encode_metadata, encode_toc, encode_toc_list, ) class ...
4
assert
numeric_literal
tests/test_epub_transcode.py
test_encode_multiple_fields
TestEncodeMetadata
310
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement from epub_translator.xml import decode_friendly, encode_friendly class TestFriendlyXML(unittest.TestCase): def test_decode_nested_tags(self): """测试解码嵌套标签""" xml_str = "<div><p>First</p><p>Second</p></div>" elements = li...
3)
self.assertEqual
numeric_literal
tests/test_xml_friendly.py
test_decode_nested_tags
TestFriendlyXML
34
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.spines import search_spine_paths from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture spines_temp_dir = create_temp_dir_fixture("spines") class TestSpinePathsValidation: def test_spine_paths_are_unique(self, spines_temp_dir):...
len(unique_paths)
assert
func_call
tests/test_spines.py
test_spine_paths_are_unique
TestSpinePathsValidation
202
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement from epub_translator.xml import decode_friendly, encode_friendly class TestFriendlyXML(unittest.TestCase): def test_decode_simple_tag(self): """测试解码简单的标签""" xml_str = "<p>Hello World</p>" elements = list(decode_friendly...
1)
self.assertEqual
numeric_literal
tests/test_xml_friendly.py
test_decode_simple_tag
TestFriendlyXML
15
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.spines import search_spine_paths from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture spines_temp_dir = create_temp_dir_fixture("spines") class TestSearchSpinePathsEpub2: def test_search_little_prince_spines(self, spines_temp...
0
assert
numeric_literal
tests/test_spines.py
test_search_little_prince_spines
TestSearchSpinePathsEpub2
25
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestReadMetadata: def test_read_little_prince_met...
2
assert
numeric_literal
tests/test_metadata.py
test_read_little_prince_metadata
TestReadMetadata
36
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement, fromstring, tostring from epub_translator.segment.text_segment import combine_text_segments, search_text_segments class TestSearchTextSegments(unittest.TestCase): def test_search_text_and_tail(self): """测试提取 TEXT 和 TAIL 文本""" ...
3)
self.assertEqual
numeric_literal
tests/test_text_segment.py
test_search_text_and_tail
TestSearchTextSegments
41
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement from epub_translator.xml import decode_friendly, encode_friendly class TestFriendlyXML(unittest.TestCase): def test_decode_simple_tag(self): """测试解码简单的标签""" xml_str = "<p>Hello World</p>" elements = list(decode_friendly...
"p")
self.assertEqual
string_literal
tests/test_xml_friendly.py
test_decode_simple_tag
TestFriendlyXML
16
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestReadTocEpub: def test_read_little_prince_toc(self, toc_temp_dir): """测试读...
28
assert
numeric_literal
tests/test_toc.py
test_read_little_prince_toc
TestReadTocEpub
25
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestReadMetadata: def test_read_chinese_book_meta...
0
assert
numeric_literal
tests/test_metadata.py
test_read_chinese_book_metadata
TestReadMetadata
61
null
oomol-lab/epub-translator
from xml.etree import ElementTree as ET from epub_translator.epub.metadata import MetadataField from epub_translator.epub.toc import Toc from epub_translator.translation.epub_transcode import ( decode_metadata, decode_toc, decode_toc_list, encode_metadata, encode_toc, encode_toc_list, ) class ...
2
assert
numeric_literal
tests/test_epub_transcode.py
test_encode_nested_toc
TestEncodeToc
76
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.metadata import MetadataField, read_metadata, write_metadata from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture metadata_temp_dir = create_temp_dir_fixture("metadata") class TestMetadataFieldDataClass: def test_metadata_fie...
field3
assert
variable
tests/test_metadata.py
test_metadata_field_equality
TestMetadataFieldDataClass
198
null
oomol-lab/epub-translator
from typing import Self from epub_translator.serial import Segment, split from epub_translator.serial.chunk import split_into_chunks class TestChunkBasic: def test_large_max_tokens(self): """测试 max_tokens 很大时,所有内容在一个 chunk 中""" segments = [ MockSegment.from_text("Short"), ...
1
assert
numeric_literal
tests/test_serial.py
test_large_max_tokens
TestChunkBasic
93
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_non_math_element(): """非 math 元素应该返回空字符串""" xml = """<div>not a math element</div>""" element = fromstring(xml) result = xml_to_latex(element) assert result ==
""
assert
string_literal
tests/test_math.py
test_non_math_element
167
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import fromstring, tostring from epub_translator.segment.inline_segment import ( InlineSegment, InlineUnexpectedIDError, InlineWrongTagCountError, search_inline_segments, ) from epub_translator.segment.text_segment import search_text_segments from epub_transla...
1)
self.assertEqual
numeric_literal
tests/test_inline_segment.py
test_create_simple_element
TestCreateElement
115
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestReadTocEpub3: def test_read_deepseek_ocr_toc(self, toc_temp_dir): """测试读...
2
assert
numeric_literal
tests/test_toc.py
test_read_deepseek_ocr_toc
TestReadTocEpub3
74
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_simple_fraction(): """简单分数""" mathml = """<math> <mfrac> <mi>a</mi> <mi>b</mi> </mfrac> </math>""" element = fromstring(mathml) result = xml_to_latex(el...
r"\frac{a}{b}"
assert
complex_expr
tests/test_math.py
test_simple_fraction
62
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.spines import search_spine_paths from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture spines_temp_dir = create_temp_dir_fixture("spines") class TestSpinePathsStructure: def test_spine_paths_order(self, spines_temp_dir): ...
spine_paths_2
assert
variable
tests/test_spines.py
test_spine_paths_order
TestSpinePathsStructure
164
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestTocDataClass: def test_full_href_with_none_href(self): """测试 href 为 None...
None
assert
none_literal
tests/test_toc.py
test_full_href_with_none_href
TestTocDataClass
272
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_superscript(): """上标""" mathml = """<math> <msup> <mi>x</mi> <mn>2</mn> </msup> </math>""" element = fromstring(mathml) result = xml_to_latex(element) ...
r"x^{2}"
assert
complex_expr
tests/test_math.py
test_superscript
92
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, SubElement, fromstring, tostring from epub_translator.segment.text_segment import combine_text_segments, search_text_segments class TestSearchTextSegments(unittest.TestCase): def test_search_simple_text(self): """测试提取简单文本""" root = Elemen...
1)
self.assertEqual
numeric_literal
tests/test_text_segment.py
test_search_simple_text
TestSearchTextSegments
17
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import fromstring, tostring from epub_translator.segment.inline_segment import ( InlineSegment, InlineUnexpectedIDError, InlineWrongTagCountError, search_inline_segments, ) from epub_translator.segment.text_segment import search_text_segments from epub_transla...
3)
self.assertEqual
numeric_literal
tests/test_inline_segment.py
test_parent_with_text_and_child_blocks_not_merged
TestEdgeCases
328
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.spines import search_spine_paths from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture spines_temp_dir = create_temp_dir_fixture("spines") class TestSearchSpinePathsEpub2: def test_search_little_prince_spines(self, spines_temp...
[".xhtml", ".html", ".htm"]
assert
collection
tests/test_spines.py
test_search_little_prince_spines
TestSearchSpinePathsEpub2
40
null
oomol-lab/epub-translator
from xml.etree import ElementTree as ET from epub_translator.epub.metadata import MetadataField from epub_translator.epub.toc import Toc from epub_translator.translation.epub_transcode import ( decode_metadata, decode_toc, decode_toc_list, encode_metadata, encode_toc, encode_toc_list, ) class ...
1
assert
numeric_literal
tests/test_epub_transcode.py
test_toc_list_roundtrip
TestTocRoundTrip
277
null
oomol-lab/epub-translator
import unittest from epub_translator.xml.self_closing import self_close_void_elements, unclose_void_elements class TestSelfCloseVoidElements(unittest.TestCase): def test_empty_string(self): """测试空字符串""" result = self_close_void_elements("") self.assertEqual(result,
"")
self.assertEqual
string_literal
tests/test_self_closing.py
test_empty_string
TestSelfCloseVoidElements
231
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_greek_letters(): """希腊字母""" mathml = """<math> <mrow> <mo>π</mo> <mo>=</mo> <mn>3.14</mn> </mrow> </math>""" element = fromstring(mathml) re...
r"\pi=3.14"
assert
complex_expr
tests/test_math.py
test_greek_letters
158
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.toc import Toc, read_toc, write_toc from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture toc_temp_dir = create_temp_dir_fixture("toc") class TestWriteTocEpub: def test_remove_toc_item(self, toc_temp_dir): """测试删除目录项""...
"3"
assert
string_literal
tests/test_toc.py
test_remove_toc_item
TestWriteTocEpub
180
null
oomol-lab/epub-translator
from xml.etree import ElementTree as ET from epub_translator.epub.metadata import MetadataField from epub_translator.epub.toc import Toc from epub_translator.translation.epub_transcode import ( decode_metadata, decode_toc, decode_toc_list, encode_metadata, encode_toc, encode_toc_list, ) class ...
0
assert
numeric_literal
tests/test_epub_transcode.py
test_decode_simple_toc
TestDecodeToc
158
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_fraction_with_subscript(): """测试你的 EPUB 文件中实际的例子:分数 + 下标 + 箭头""" mathml = """<math display="inline"> <mrow> <mrow> <mfrac> <mrow> <msub> <m...
r"\frac{S_{1}}{S}\rightarrow\frac{S_{2}}{a}"
assert
complex_expr
tests/test_math.py
test_fraction_with_subscript
47
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_subscript(): """下标""" mathml = """<math> <msub> <mi>x</mi> <mn>2</mn> </msub> </math>""" element = fromstring(mathml) result = xml_to_latex(element) ...
r"x_{2}"
assert
complex_expr
tests/test_math.py
test_subscript
77
null
oomol-lab/epub-translator
from typing import Self from epub_translator.serial import Segment, split from epub_translator.serial.chunk import split_into_chunks class TestTruncation: def test_truncate_after_head(self): """测试 truncate_after_head 方法""" seg = MockSegment.from_text("HelloWorld") # 10 tokens truncated ...
5
assert
numeric_literal
tests/test_serial.py
test_truncate_after_head
TestTruncation
182
null
oomol-lab/epub-translator
import unittest from epub_translator.xml.self_closing import self_close_void_elements, unclose_void_elements class TestSelfCloseVoidElements(unittest.TestCase): def test_complex_real_world_html(self): """测试真实世界的复杂 HTML""" input_html = """<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">...
expected)
self.assertEqual
variable
tests/test_self_closing.py
test_complex_real_world_html
TestSelfCloseVoidElements
220
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, fromstring, tostring from epub_translator.segment import search_text_segments from epub_translator.utils import normalize_whitespace from epub_translator.xml import iter_with_stack from epub_translator.xml_translator.stream_mapper import InlineSegmentMapping f...
element_to_string(root))
self.assertEqual
func_call
tests/test_submitter.py
test_empty_mappings
TestSubmitEdgeCases
235
null
oomol-lab/epub-translator
import io import unittest from typing import cast from xml.etree.ElementTree import Element from epub_translator.xml.xml_like import XMLLikeNode class TestXMLLikeNode(unittest.TestCase): def test_header_with_whitespace_and_newlines(self): """测试 header 中包含大量空白和换行的情况""" original_content = b""" <?x...
header_part)
self.assertIn
variable
tests/test_xml_like.py
test_header_with_whitespace_and_newlines
TestXMLLikeNode
212
null
oomol-lab/epub-translator
from pathlib import Path from epub_translator.epub.spines import search_spine_paths from epub_translator.epub.zip import Zip from tests.utils import create_temp_dir_fixture spines_temp_dir = create_temp_dir_fixture("spines") class TestSpinePathsValidation: def test_spine_paths_file_extensions(self, spines_temp_...
valid_extensions
assert
variable
tests/test_spines.py
test_spine_paths_file_extensions
TestSpinePathsValidation
217
null
oomol-lab/epub-translator
import unittest from epub_translator.xml.self_closing import self_close_void_elements, unclose_void_elements class TestEdgeCases(unittest.TestCase): def test_malformed_html(self): """测试畸形 HTML(不应崩溃)""" # 这些情况下函数应该尽力处理,不崩溃 cases = [ "<br<", # 不完整的标签 '<meta charset=...
str)
self.assertIsInstance
variable
tests/test_self_closing.py
test_malformed_html
TestEdgeCases
367
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_nested_fraction(): """嵌套分数""" mathml = """<math> <mfrac> <mfrac> <mi>a</mi> <mi>b</mi> </mfrac> <mi>c</mi> </mfrac> <...
r"\frac{\frac{a}{b}}{c}"
assert
complex_expr
tests/test_math.py
test_nested_fraction
124
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import fromstring, tostring from epub_translator.segment.inline_segment import ( InlineSegment, InlineUnexpectedIDError, InlineWrongTagCountError, search_inline_segments, ) from epub_translator.segment.text_segment import search_text_segments from epub_transla...
None
assert
none_literal
tests/test_inline_segment.py
test_collect_simple_inline
TestCollectInlineSegment
32
null
oomol-lab/epub-translator
import unittest from xml.etree.ElementTree import Element, fromstring, tostring from epub_translator.segment import search_text_segments from epub_translator.utils import normalize_whitespace from epub_translator.xml import iter_with_stack from epub_translator.xml_translator.stream_mapper import InlineSegmentMapping f...
"应该包含 math 元素的译文")
self.assertIn
string_literal
tests/test_submitter.py
test_bug_indirect_child_in_platform_structure
TestBugReproduction
365
null
oomol-lab/epub-translator
from xml.etree.ElementTree import fromstring from epub_translator.epub.math import xml_to_latex def test_operator_mapping(): """运算符映射""" mathml = """<math> <mrow> <mi>a</mi> <mo>×</mo> <mi>b</mi> <mo>≤</mo> <mi>c</mi> </mrow> </ma...
r"a\timesb\leqc"
assert
complex_expr
tests/test_math.py
test_operator_mapping
142
null
stanford-cs336/assignment1-basics
from __future__ import annotations import json import os import resource import sys import psutil import pytest import tiktoken from .adapters import get_tokenizer from .common import FIXTURES_PATH, gpt2_bytes_to_unicode VOCAB_PATH = FIXTURES_PATH / "gpt2_vocab.json" MERGES_PATH = FIXTURES_PATH / "gpt2_merges.txt" ...
["s"]
assert
collection
tests/test_tokenizer.py
test_single_character_matches_tiktoken
131
null
stanford-cs336/assignment1-basics
import math from collections import Counter import numpy as np import pytest from .adapters import run_get_batch def test_get_batch(): dataset = np.arange(0, 100) context_length = 7 batch_size = 32 device = "cpu" # Sanity check to make sure that the random samples are indeed somewhat random. ...
0
assert
numeric_literal
tests/test_data.py
test_get_batch
39
null
stanford-cs336/assignment1-basics
import json import time from .adapters import run_train_bpe from .common import FIXTURES_PATH, gpt2_bytes_to_unicode def test_train_bpe(): input_path = FIXTURES_PATH / "corpus.en" vocab, merges = run_train_bpe( input_path=input_path, vocab_size=500, special_tokens=["<|endoftext|>"], ...
set(reference_vocab.values())
assert
func_call
tests/test_train_bpe.py
test_train_bpe
62
null
stanford-cs336/assignment1-basics
import numpy import torch from .adapters import get_adamw_cls, run_get_lr_cosine_schedule def _optimize(opt_class) -> torch.Tensor: torch.manual_seed(42) model = torch.nn.Linear(3, 2, bias=False) opt = opt_class( model.parameters(), lr=1e-3, weight_decay=0.01, betas=(0.9, 0...
numpy.array(expected_lrs))
assert_*
func_call
tests/test_optimizer.py
test_get_lr_cosine_schedule
95
null
stanford-cs336/assignment1-basics
from typing import TypeVar import numpy as np import pytest import os from pathlib import Path import torch from torch import Tensor import pickle def _canonicalize_array(arr: _A) -> np.ndarray: if isinstance(arr, Tensor): arr = arr.detach().cpu().numpy() return arr class Snapshot: def __init__( ...
expected_data[key]
assert
complex_expr
tests/conftest.py
assert_match
Snapshot
146
null
stanford-cs336/assignment1-basics
import json import time from .adapters import run_train_bpe from .common import FIXTURES_PATH, gpt2_bytes_to_unicode def test_train_bpe_special_tokens(snapshot): """ Ensure that the special tokens are added to the vocabulary and not merged with other tokens. """ input_path = FIXTURES_PATH / "tinys...
word_bytes
assert
variable
tests/test_train_bpe.py
test_train_bpe_special_tokens
80
null
stanford-cs336/assignment1-basics
from typing import TypeVar import numpy as np import pytest import os from pathlib import Path import torch from torch import Tensor import pickle def _canonicalize_array(arr: _A) -> np.ndarray: if isinstance(arr, Tensor): arr = arr.detach().cpu().numpy() return arr class NumpySnapshot: def __ini...
None
assert
none_literal
tests/conftest.py
assert_match
NumpySnapshot
65
null
stanford-cs336/assignment1-basics
import json import time from .adapters import run_train_bpe from .common import FIXTURES_PATH, gpt2_bytes_to_unicode def test_train_bpe_speed(): """ Ensure that BPE training is relatively efficient by measuring training time on this small dataset and throwing an error if it takes more than 1.5 seconds. ...
1.5
assert
numeric_literal
tests/test_train_bpe.py
test_train_bpe_speed
24
null
stanford-cs336/assignment1-basics
import numpy import torch import torch.nn.functional as F from torch.nn.utils.clip_grad import clip_grad_norm_ from .adapters import run_cross_entropy, run_gradient_clipping, run_softmax def test_gradient_clipping(): tensors = [torch.randn((5, 5)) for _ in range(6)] max_norm = 1e-2 t1 = tuple(torch.nn.Pa...
t1_c_grad.detach().numpy())
assert_*
func_call
tests/test_nn_utils.py
test_gradient_clipping
85
null
stanford-cs336/assignment1-basics
import json import time from .adapters import run_train_bpe from .common import FIXTURES_PATH, gpt2_bytes_to_unicode def test_train_bpe(): input_path = FIXTURES_PATH / "corpus.en" vocab, merges = run_train_bpe( input_path=input_path, vocab_size=500, special_tokens=["<|endoftext|>"], ...
reference_merges
assert
variable
tests/test_train_bpe.py
test_train_bpe
50
null
stanford-cs336/assignment1-basics
from typing import TypeVar import numpy as np import pytest import os from pathlib import Path import torch from torch import Tensor import pickle def _canonicalize_array(arr: _A) -> np.ndarray: if isinstance(arr, Tensor): arr = arr.detach().cpu().numpy() return arr class Snapshot: def __init__( ...
expected_data
assert
variable
tests/conftest.py
assert_match
Snapshot
150
null
stanford-cs336/assignment1-basics
from __future__ import annotations import json import os import resource import sys import psutil import pytest import tiktoken from .adapters import get_tokenizer from .common import FIXTURES_PATH, gpt2_bytes_to_unicode VOCAB_PATH = FIXTURES_PATH / "gpt2_vocab.json" MERGES_PATH = FIXTURES_PATH / "gpt2_merges.txt" ...
1
assert
numeric_literal
tests/test_tokenizer.py
test_overlapping_special_tokens
259
null
stanford-cs336/assignment1-basics
import math from collections import Counter import numpy as np import pytest from .adapters import run_get_batch def test_get_batch(): dataset = np.arange(0, 100) context_length = 7 batch_size = 32 device = "cpu" # Sanity check to make sure that the random samples are indeed somewhat random. ...
y.detach().numpy())
assert_*
func_call
tests/test_data.py
test_get_batch
32
null
stanford-cs336/assignment1-basics
import numpy import torch import torch.nn as nn import torch.nn.functional as F from .adapters import get_adamw_cls, run_load_checkpoint, run_save_checkpoint def are_optimizers_equal(optimizer1_state_dict, optimizer2_state_dict, atol=1e-8, rtol=1e-5): # Check if the keys of the main dictionaries are equal (e.g., ...
new_model_state[key].detach().numpy())
assert_*
func_call
tests/test_serialization.py
test_checkpointing
116
null
stanford-cs336/assignment1-basics
import numpy import torch import torch.nn as nn import torch.nn.functional as F from .adapters import get_adamw_cls, run_load_checkpoint, run_save_checkpoint def are_optimizers_equal(optimizer1_state_dict, optimizer2_state_dict, atol=1e-8, rtol=1e-5): # Check if the keys of the main dictionaries are equal (e.g., ...
set(new_optimizer_state.keys())
assert
func_call
tests/test_serialization.py
test_checkpointing
112
null
stanford-cs336/assignment1-basics
from __future__ import annotations import json import os import resource import sys import psutil import pytest import tiktoken from .adapters import get_tokenizer from .common import FIXTURES_PATH, gpt2_bytes_to_unicode VOCAB_PATH = FIXTURES_PATH / "gpt2_vocab.json" MERGES_PATH = FIXTURES_PATH / "gpt2_merges.txt" ...
reference_ids
assert
variable
tests/test_tokenizer.py
test_empty_matches_tiktoken
98
null
stanford-cs336/assignment1-basics
import json import time from .adapters import run_train_bpe from .common import FIXTURES_PATH, gpt2_bytes_to_unicode def test_train_bpe_special_tokens(snapshot): """ Ensure that the special tokens are added to the vocabulary and not merged with other tokens. """ input_path = FIXTURES_PATH / "tinys...
{ "vocab_keys": set(vocab.keys()), "vocab_values": set(vocab.values()), "merges": merges, })
assert_*
collection
tests/test_train_bpe.py
test_train_bpe_special_tokens
82
null
stanford-cs336/assignment1-basics
from __future__ import annotations import json import os import resource import sys import psutil import pytest import tiktoken from .adapters import get_tokenizer from .common import FIXTURES_PATH, gpt2_bytes_to_unicode VOCAB_PATH = FIXTURES_PATH / "gpt2_vocab.json" MERGES_PATH = FIXTURES_PATH / "gpt2_merges.txt" ...
[]
assert
collection
tests/test_tokenizer.py
test_empty_matches_tiktoken
101
null
stanford-cs336/assignment1-basics
import numpy import torch import torch.nn as nn import torch.nn.functional as F from .adapters import get_adamw_cls, run_load_checkpoint, run_save_checkpoint def are_optimizers_equal(optimizer1_state_dict, optimizer2_state_dict, atol=1e-8, rtol=1e-5): # Check if the keys of the main dictionaries are equal (e.g., ...
set(new_model_state.keys())
assert
func_call
tests/test_serialization.py
test_checkpointing
111
null
stanford-cs336/assignment1-basics
import json import time from .adapters import run_train_bpe from .common import FIXTURES_PATH, gpt2_bytes_to_unicode def test_train_bpe(): input_path = FIXTURES_PATH / "corpus.en" vocab, merges = run_train_bpe( input_path=input_path, vocab_size=500, special_tokens=["<|endoftext|>"], ...
set(reference_vocab.keys())
assert
func_call
tests/test_train_bpe.py
test_train_bpe
61
null
stanford-cs336/assignment1-basics
import numpy import torch import torch.nn.functional as F from torch.nn.utils.clip_grad import clip_grad_norm_ from .adapters import run_cross_entropy, run_gradient_clipping, run_softmax def test_softmax_matches_pytorch(): x = torch.tensor( [ [0.4655, 0.8303, 0.9608, 0.9656, 0.6840], ...
expected.detach().numpy())
assert_*
func_call
tests/test_nn_utils.py
test_softmax_matches_pytorch
18
null
stanford-cs336/assignment1-basics
import numpy import torch from .adapters import get_adamw_cls, run_get_lr_cosine_schedule def _optimize(opt_class) -> torch.Tensor: torch.manual_seed(42) model = torch.nn.Linear(3, 2, bias=False) opt = opt_class( model.parameters(), lr=1e-3, weight_decay=0.01, betas=(0.9, 0...
actual_weights)
assert_*
variable
tests/test_optimizer.py
test_adamw
46
null
stanford-cs336/assignment1-basics
from __future__ import annotations import json import os import resource import sys import psutil import pytest import tiktoken from .adapters import get_tokenizer from .common import FIXTURES_PATH, gpt2_bytes_to_unicode VOCAB_PATH = FIXTURES_PATH / "gpt2_vocab.json" MERGES_PATH = FIXTURES_PATH / "gpt2_merges.txt" ...
3
assert
numeric_literal
tests/test_tokenizer.py
test_roundtrip_unicode_string_with_special_tokens
227
null
stanford-cs336/assignment1-basics
import numpy import torch import torch.nn.functional as F from torch.nn.utils.clip_grad import clip_grad_norm_ from .adapters import run_cross_entropy, run_gradient_clipping, run_softmax def test_cross_entropy(): inputs = torch.tensor( [ [ [0.1088, 0.1060, 0.6683, 0.5131, 0.064...
large_expected_cross_entropy.detach().numpy())
assert_*
func_call
tests/test_nn_utils.py
test_cross_entropy
55
null
stanford-cs336/assignment1-basics
import math from collections import Counter import numpy as np import pytest from .adapters import run_get_batch def test_get_batch(): dataset = np.arange(0, 100) context_length = 7 batch_size = 32 device = "cpu" # Sanity check to make sure that the random samples are indeed somewhat random. ...
(RuntimeError, AssertionError))
pytest.raises
collection
tests/test_data.py
test_get_batch
62
null
stanford-cs336/assignment1-basics
from einops import rearrange import numpy import torch import torch.nn.functional as F from .adapters import ( run_multihead_self_attention_with_rope, run_rope, run_silu, run_multihead_self_attention, run_swiglu, run_rmsnorm, run_scaled_dot_product_attention, run_transformer_block, ...
expected_output.detach().numpy())
assert_*
func_call
tests/test_model.py
test_silu_matches_pytorch
202
null