Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions tests/integration/test_collect_metrics_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import yaml

from training_data_packer.collect_metrics import main
from training_data_packer.utils.metadata import Metadata


class TestCollectMetricsTree(unittest.TestCase):
Expand All @@ -16,12 +17,14 @@ def test_collect_metrics_tree(self):
tmp_path = Path(tmp_dir)

# Create metadata.yaml
metadata = {
"release": {"default": {"pack": "tree"}, "part1": {}, "part2": {}},
"source": {"part1": {}, "part2": {}},
}
metadata = Metadata(
{
"release": {"default": {"pack": "tree"}, "part1": {}, "part2": {}},
"source": {"part1": {}, "part2": {}},
}
)
with open(tmp_path / "metadata.yaml", "w") as f:
yaml.dump(metadata, f)
yaml.dump(metadata.data, f)

# Create release_raw structure
release_raw = tmp_path / "release-raw"
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_propella_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from training_data_packer import propella_merge
from training_data_packer.propella_merge import process_file
from training_data_packer.utils.file import GenericJsonlReader, JsonlZstWriter
from training_data_packer.utils.metadata import Metadata
from training_data_packer.utils.metrics import read_metrics_from_file


Expand All @@ -15,7 +16,7 @@ def test_process_skip_existing_file(self):
Test that process_file skips files that already exist in the output directory.
"""
with TemporaryDirectory() as test_dir:
metadata = {"id": "id", "suffix": ".jsonl.zst"}
metadata = Metadata({"id": "id", "suffix": ".jsonl.zst"})
source_name = "test_file.jsonl.zst"
propella_dir = Path(test_dir).joinpath("propella-4b")
propella_dir.mkdir(parents=True)
Expand Down
155 changes: 83 additions & 72 deletions tests/mode/test_release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from training_data_packer.mode.release import parallel_package_pipeline
from training_data_packer.utils.metadata import Metadata


class TestParallelPackagePipeline(unittest.TestCase):
Expand All @@ -21,21 +22,23 @@ def test_first(self):
"tgt_lang": "als_Latn",
}
]
metadata = {
"_internal": {"parallel": True},
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
metadata = Metadata(
{
"_internal": {"parallel": True},
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
},
},
},
}
}
)
part_config = {}
piis = iter([])
contaminations = iter([])
Expand Down Expand Up @@ -71,21 +74,23 @@ def test_pii_without_id(self):
"tgt_lang": "als_Latn",
},
]
metadata = {
"_internal": {"parallel": True},
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
metadata = Metadata(
{
"_internal": {"parallel": True},
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
},
},
},
}
}
)
part_config = {}
piis = iter([{"hash": "7ea462d1386566606429b6ba9c3adfe39d742c742c835b464a8e8ccdfdf71452"}])
contaminations = iter([])
Expand Down Expand Up @@ -122,22 +127,24 @@ def test_pii_with_id(self):
"tgt_lang": "als_Latn",
},
]
metadata = {
"_internal": {"parallel": True},
"id": "id",
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
metadata = Metadata(
{
"_internal": {"parallel": True},
"id": "id",
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
},
},
},
}
}
)
part_config = {}
piis = iter([{"id": "2"}])
contaminations = iter([])
Expand Down Expand Up @@ -172,21 +179,23 @@ def test_contamination_without_id(self):
"tgt_lang": "als_Latn",
},
]
metadata = {
"_internal": {"parallel": True},
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
metadata = Metadata(
{
"_internal": {"parallel": True},
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
},
},
},
}
}
)
part_config = {}
piis = iter([])
contaminations = iter([{"hash": "7ea462d1386566606429b6ba9c3adfe39d742c742c835b464a8e8ccdfdf71452"}])
Expand Down Expand Up @@ -223,22 +232,24 @@ def test_contamination_with_id(self):
"tgt_lang": "als_Latn",
},
]
metadata = {
"_internal": {"parallel": True},
"id": "id",
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
metadata = Metadata(
{
"_internal": {"parallel": True},
"id": "id",
"text": "text",
"parallel": {
"input": "source",
"source": {
"text": "source_text",
"language": "src_lang",
},
"target": {
"text": "target_text",
"language": "tgt_lang",
},
},
},
}
}
)
part_config = {}
piis = iter([])
contaminations = iter([{"id": "1"}])
Expand Down
45 changes: 24 additions & 21 deletions tests/processor/sample/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from parameterized import parameterized

from training_data_packer.processor.sample.sampler import DynamicSampler, convert_to_type, sampler_factory
from training_data_packer.utils.metadata import Metadata


class TestDynamicSampler(unittest.TestCase):
Expand Down Expand Up @@ -75,52 +76,54 @@ def test_convert_to_type_preserves_dict(self):

class TestSamplerFactory(unittest.TestCase):
def test_sample_not_set(self):
metadata = {"release": {"foo": {}}}
src_file = "blabla/foo/bla"
metadata = Metadata({"release": {"foo": {}}})
src_file = Path("blabla/foo/bla")
in_data = iter([])
result_iter, _ = sampler_factory(in_data, metadata, src_file)
self.assertEqual(in_data, result_iter)

def test_sample_is_full(self):
metadata = {"release": {"foo": {"sample": "full"}}}
src_file = "blabla/foo/bla"
metadata = Metadata({"release": {"foo": {"sample": "full"}}})
src_file = Path("blabla/foo/bla")
in_data = iter([])
result_iter, _ = sampler_factory(in_data, metadata, src_file)
self.assertEqual(in_data, result_iter)

def test_sample_is_random(self):
metadata = {"release": {"foo": {"sample": "random", "budget": "75%"}}}
src_file = "blabla/foo/bla"
metadata = Metadata({"release": {"foo": {"sample": "random", "budget": "75%"}}})
src_file = Path("blabla/foo/bla")
in_data = iter([])
result_iter, _ = sampler_factory(in_data, metadata, src_file)
self.assertIsInstance(result_iter, itertools.filterfalse)

def test_sample_is_wds_register(self):
metadata = {"release": {"foo": {"sample": "wds+register"}}}
src_file = "blabla/foo/bla"
metadata = Metadata({"release": {"foo": {"sample": "wds+register"}}})
src_file = Path("blabla/foo/bla")
in_data = iter([])
result_iter, _ = sampler_factory(in_data, metadata, src_file)
self.assertIsInstance(result_iter, itertools.chain)

def test_sample_is_dynamic(self):
metadata = {
"_internal": {"collection_dir": Path(os.getcwd())},
"release": {
"foo": {
"sample": "dynamic",
"parameters": {"para": "5"},
"filter": "tests/resources/sampler/test_sampler.py",
}
},
}
src_file = "blabla/foo/bla"
metadata = Metadata(
{
"_internal": {"collection_dir": Path(os.getcwd())},
"release": {
"foo": {
"sample": "dynamic",
"parameters": {"para": "5"},
"filter": "tests/resources/sampler/test_sampler.py",
}
},
}
)
src_file = Path("blabla/foo/bla")
in_data = iter([])
result_iter, _ = sampler_factory(in_data, metadata, src_file)
self.assertIsInstance(result_iter, itertools.chain)

def test_sample_illegall(self):
metadata = {"release": {"foo": {"sample": "illegal"}}}
src_file = "blabla/foo/bla"
metadata = Metadata({"release": {"foo": {"sample": "illegal"}}})
src_file = Path("blabla/foo/bla")
in_data = iter([])
with self.assertRaises(ValueError):
sampler_factory(in_data, metadata, src_file)
13 changes: 8 additions & 5 deletions tests/processor/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from parameterized import parameterized

from training_data_packer.processor.clean import AlignFieldNames, field_scrubber_factory
from training_data_packer.utils.metadata import Metadata


class TestAlignFieldNames(unittest.TestCase):
Expand All @@ -11,7 +12,7 @@ def test_no_mapping_needed(self):
{"id": "1234", "text": "Happy"},
{"id": "1235", "text": "Gazonk"},
]
align_it = AlignFieldNames(iter(src_indata), {"id": "id", "text": "text"})
align_it = AlignFieldNames(iter(src_indata), Metadata({"id": "id", "text": "text"}))
align_list = list(align_it)
self.assertEqual(align_list, src_indata)

Expand All @@ -20,7 +21,7 @@ def test_no_mapping_fields(self):
{"id": "1234", "text": "Happy"},
{"id": "1235", "text": "Gazonk"},
]
align_it = AlignFieldNames(iter(src_indata), {})
align_it = AlignFieldNames(iter(src_indata), Metadata({}))
align_list = list(align_it)
self.assertEqual(align_list, src_indata)

Expand All @@ -33,7 +34,7 @@ def test_map_id(self):
{"id": "1234", "text": "Happy"},
{"id": "1235", "text": "Gazonk"},
]
align_it = AlignFieldNames(iter(src_indata), {"id": "warcid", "text": "text"})
align_it = AlignFieldNames(iter(src_indata), Metadata({"id": "warcid", "text": "text"}))
align_list = list(align_it)
self.assertEqual(align_list, expected)

Expand All @@ -46,7 +47,7 @@ def test_map_text(self):
{"id": "1234", "text": "Happy"},
{"id": "1235", "text": "Gazonk"},
]
align_it = AlignFieldNames(iter(src_indata), {"id": "id", "text": "context"})
align_it = AlignFieldNames(iter(src_indata), Metadata({"id": "id", "text": "context"}))
align_list = list(align_it)
self.assertEqual(align_list, expected)

Expand All @@ -59,7 +60,9 @@ def test_hierarchy_text(self):
{"id": "1234", "metadata": {}, "text": "Happy"},
{"id": "1235", "metadata": {}, "text": "Gazonk"},
]
align_it = AlignFieldNames(iter(src_indata), {"id": "metadata.int-id", "text": "context", "doc_s": "doc_score"})
align_it = AlignFieldNames(
iter(src_indata), Metadata({"id": "metadata.int-id", "text": "context", "doc_s": "doc_score"})
)
align_list = list(align_it)
self.assertEqual(align_list, expected)

Expand Down
2 changes: 1 addition & 1 deletion tests/processor/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class TestFilterOnBlocklist(unittest.TestCase):
def test_filtering_with_metrics(self):
blocklist = ["2", "4", "7"]
blocklist = {"2", "4", "7"}
input_elements = [
{"id": "1", "name": "block1"},
{"id": "2", "name": "block1"},
Expand Down
Loading