MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / TestDataModule

Class TestDataModule

data_test.py:35–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 df.to_csv(file_path, index=False)
34
35class TestDataModule(unittest.TestCase):
36 @classmethod
37 def setUpClass(cls):
38 cls.tokenizer = MockTokenizer()
39
40 # Create temporary directory for test files
41 cls.temp_dir = tempfile.TemporaryDirectory()
42 cls.temp_path = cls.temp_dir.name
43
44 # Create sample CSV data
45 cls.csv_data = {
46 'history_item_title': ["['Item A', 'Item B']", "['Item C', 'Item D']"],
47 'item_title': ['Item E', 'Item F'],
48 'history_item_id': ["['1', '2']", "['3', '4']"],
49 'item_id': ['5', '6'],
50 'history_item_sid': ["['SID1', 'SID2']", "['SID3', 'SID4']"],
51 'item_sid': ['SID5', 'SID6'],
52 'user_id_original_str': ['user1', 'user2'],
53 'e_token': ['[CTX_HOMEPAGE]', '[CTX_SEARCH]']
54 }
55 cls.csv_file = os.path.join(cls.temp_path, 'test_data.csv')
56 create_minimal_csv(cls.csv_file, cls.csv_data)
57
58 # Create sample item features JSON
59 cls.item_features = {
60 '5': {'title': 'Item E', 'description': 'Description of Item E', 'item_type': 'O'},
61 '6': {'title': 'Item F', 'description': 'Description of Item F', 'item_type': 'I'}
62 }
63 cls.item_file = os.path.join(cls.temp_path, 'test.item.json')
64 with open(cls.item_file, 'w') as f:
65 json.dump(cls.item_features, f)
66
67 # Create sample indices JSON
68 cls.indices = {
69 '5': ['SID5_1', 'SID5_2', 'SID5_3'],
70 '6': ['SID6_1', 'SID6_2', 'SID6_3']
71 }
72 cls.index_file = os.path.join(cls.temp_path, 'test.index.json')
73 with open(cls.index_file, 'w') as f:
74 json.dump(cls.indices, f)
75
76 # Create sample user preference JSON
77 cls.user_preference_data = [
78 {
79 'user': 'user1',
80 'user_preference': 'Likes action games',
81 'context': {
82 'history_items': ['1', '2'],
83 'target_item': '5'
84 },
85 'split': 'train'
86 },
87 {
88 'user': 'user2',
89 'user_preference': 'Prefers strategy games',
90 'context': {
91 'history_items': ['3', '4'],
92 'target_item': '6'

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected