def test_container_tree_tags(self):
        '''test adding tags to a container tree'''
        print("Testing creation with tags.")

        from containertree import ContainerFileTree
        import requests

        database = "https://singularityhub.github.io/api/files"
        containers = requests.get(database).json()

        tree = ContainerFileTree("vanessa/salad")
        entry1 = containers[0]
        entry2 = containers[1]

        tag1 = entry1['collection']
        #'54r4/sara-server-vre'
        tag2 = entry2['collection']
        #'A33a/sjupyter'

        tree = ContainerFileTree(entry1['url'], tag=tag1)

        self.assertTrue('54r4/sara-server-vre' in tree.root.tags)

        # Update the container tree with the second container
        tree.update(entry2['url'], tag=tag2)
        self.assertTrue('54r4/sara-server-vre' in tree.root.tags)
        self.assertTrue('A33a/sjupyter' in tree.root.tags)

        # calculate similarity between tags
        tags = tree.root.tags
        scores = tree.similarity_score(tree.root.tags)

        # {'diff': 44185,
        # 'same': 12201,
        # 'score': 0.21638349945021815,
        # 'tags': ['54r4/sara-server-vre', 'A33a/sjupyter'],
        # 'total': 56386}

        self.assertEqual(scores['diff'], 44185)
        self.assertEqual(scores['same'], 12201)
Exemple #2
0
print('Selecting container from %s...' % database)
containers = requests.get(database).json()
container1 = containers[0]
container2 = containers[1]

# Google Container Diff Structure
tree = ContainerFileTree(container1['url'], tag=container1['collection'])

# Add the second container to the tree
tree.update(container2['url'], tag=container2['collection'])

# All the containers (tags) represented in the tree
tags = tree.root.tags

# Calculate the similarity
scores = tree.similarity_score(tags)

# {'diff': 44185,
# 'same': 12201,
# 'score': 0.21638349945021815,
# 'tags': ['54r4/sara-server-vre', 'A33a/sjupyter'],
# 'total': 56386}

# We can now generate a matrix of similarity scores for containers!
# Let's build from scratch

print('Generating comparison tree!')
tree = ContainerFileTree(containers[0]['url'], tag=containers[0]['collection'])

names = []
for c in range(len(containers)):