Beispiel #1
0
 def test_tet_isroot1(self):
     '''
     test isroot true in tet
     '''
     username = '******'
     test_objekt = tet.TET(root=username)
     self.assertTrue(test_objekt.isroot(username))
Beispiel #2
0
 def test_tet_tostring1(self):
     '''
     test tostring in simple tet
     '''
     username = '******'
     test_objekt = tet.TET(root=username)
     self.assertEqual(test_objekt.tostring(), '[u:1234]')
Beispiel #3
0
 def test_tet_isroot2(self):
     '''
     test isroot false in tet
     '''
     username = '******'
     test_objekt = tet.TET(root=username)
     self.assertFalse(test_objekt.isroot('lars'))
Beispiel #4
0
 def test_tet_count_children1(self):
     '''
     test count_children in tet without children
     '''
     username = '******'
     test_objekt = tet.TET(root=username)
     self.assertEqual(test_objekt.count_children(), {})
Beispiel #5
0
 def test_tet_getroot(self):
     '''
     tests getroot in tet
     '''
     username = '******'
     test_objekt = tet.TET(root=username)
     self.assertIs(test_objekt.getroot(), username)
Beispiel #6
0
def load_tets(loadpath, limit=None):
    '''
    description: This function loads and rebuilds the tets saved by save_tets
    parameters: the loadpath is the path to the file where the tets are saved
    return: the return is a dictionary of all tets
    '''
    tets = {}
    count = 1
    with open(loadpath, 'r', encoding="utf-8") as file:
        for stringtet in tqdm(csv.reader(file)):
            tetchildren = []
            for stringsubtet in stringtet[1:]:
                stringsubtet = stringsubtet.replace('[', '').replace(']', '').split(':')
                stringsubtet[0] = stringsubtet[0].split(',')
                genres = []
                for genre in stringsubtet[0][1:]:
                    genres.append(tet.TETChild(genre))
                partlist = [tet.TETChild(stringsubtet[0][0], children=genres)]\
                     * int(stringsubtet[1])
                tetchildren = tetchildren + partlist
            tets[stringtet[0]] = tet.TET(stringtet[0], children=tetchildren)
            if limit is not None:
                if count >= limit:
                    break
                count += 1
    return tets
Beispiel #7
0
 def test_tet_getchildren(self):
     '''
     test get children in tet
     '''
     username = '******'
     children = [tet.TETChild('Lars')]
     test_objekt = tet.TET(root=username, children=children)
     self.assertEqual(test_objekt.getchildren(), children)
Beispiel #8
0
 def test_tet_count_children2(self):
     '''
     test count_children in tet with children
     '''
     username = '******'
     children = [tet.TETChild('high', children=tet.TETChild('action'))]
     test_objekt = tet.TET(root=username, children=children)
     self.assertEqual(test_objekt.count_children(),
                      {'[high,[[action]]]': 1})
Beispiel #9
0
 def test_tet_tostring2(self):
     '''
     test tostring in tet with children
     '''
     username = '******'
     children = [tet.TETChild('high', children=tet.TETChild('action'))]
     test_objekt = tet.TET(root=username, children=children)
     self.assertEqual(test_objekt.tostring(),
                      '[u:1234,[[high,[[action]]]:1]]')
Beispiel #10
0
def tet_find_tree(user, tets):
    '''
    description: This function finds the TET that has user as the root
                 if such a tree does not exist it is build
    parameters: user is a user id as a string and tets is the dictionary of tets
    return: is a TET with user as root
    '''
    if user in tets:
        return tets[user]
    return tet.TET(root=user)
Beispiel #11
0
 def test_tet_find_most_with_rating5(self):
     '''
     test find_most_with_rating in tet
     '''
     username = '******'
     children = [
         tet.TETChild('low', children=tet.TETChild('action')),
         tet.TETChild('low', children=tet.TETChild('comedy'))
     ]
     test_objekt = tet.TET(root=username, children=children)
     self.assertEqual(test_objekt.find_most_with_rating('high'),
                      [['[high,[[nohigh]]]', 0]])
Beispiel #12
0
 def test_tet_find_tree2(self):
     '''
     tests the find_tree where the tet does not exists
     '''
     username = '******'
     children = [
         tet.TETChild('high', children=tet.TETChild('action')),
         tet.TETChild('high', children=tet.TETChild('action'))
     ]
     test_tet = tet.TET(root=username, children=children)
     test_tets = {username: test_tet}
     self.assertNotEqual(build_tet.tet_find_tree('u:5678', test_tets),
                         test_tet)
Beispiel #13
0
 def test_tet_construction(self):
     '''
     test the construction of a tet
     '''
     test_objekt = tet.TET()
     self.assertIsInstance(test_objekt, tet.TET)