<commit_before>from pyshelf.search.metadata import Metadata
from elasticsearch import Elasticsearch


class TestWrapper(object):
    INIT = False

    def __init__(self, search_container):
        self.search_container = search_container
        self.es = Elasticsearch(self.search_container.es_url)
        self.index = self.search_container.es_index

    def setup_metadata(self, data):
        for doc in data:
            self.add_metadata(doc["artifactName"]["value"], doc)

        self.refresh_index()

    def add_metadata(self, key, metadata):
        self.init_metadata()
        meta = Metadata()
        meta.meta.id = key
        meta.meta.index = self.index
        meta.update_all(metadata)
        meta.save(using=self.es)

    def refresh_index(self):
        self.es.indices.refresh(index=self.index)

    def teardown_metadata(self):
        self.search_container.update_manager.remove_unlisted_documents([])
        print "HEY KYLE, INSIDE TEARDOWN" # NOCOMMIT

    def init_metadata(self):
        if not TestWrapper.INIT:
            # This is necessary as I added an analyzer with a keyword tokenizer
            # which requires an index to be closed and reopened.
            self.es.indices.delete(index=self.index, ignore=404)
            Metadata.init(index=self.index, using=self.es)
            self.es.indices.refresh(index=self.index)<commit_msg>missed a debug line<commit_after>from pyshelf.search.metadata import Metadata
from elasticsearch import Elasticsearch


class TestWrapper(object):
    INIT = False

    def __init__(self, search_container):
        self.search_container = search_container
        self.es = Elasticsearch(self.search_container.es_url)
        self.index = self.search_container.es_index

    def setup_metadata(self, data):
        for doc in data:
            self.add_metadata(doc["artifactName"]["value"], doc)

        self.refresh_index()

    def add_metadata(self, key, metadata):
        self.init_metadata()
        meta = Metadata()
        meta.meta.id = key
        meta.meta.index = self.index
        meta.update_all(metadata)
        meta.save(using=self.es)

    def refresh_index(self):
        self.es.indices.refresh(index=self.index)

    def teardown_metadata(self):
        self.search_container.update_manager.remove_unlisted_documents([])

    def init_metadata(self):
        if not TestWrapper.INIT:
            # This is necessary as I added an analyzer with a keyword tokenizer
            # which requires an index to be closed and reopened.
            self.es.indices.delete(index=self.index, ignore=404)
            Metadata.init(index=self.index, using=self.es)
            self.es.indices.refresh(index=self.index)
{'fraction_non_alphanumeric': 0.09228497600590624, 'fraction_numerical': 0.0022148394241417496, 'mean_word_length': 2.769123783031989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4712245', 'n_tokens_mistral': 794, 'n_tokens_neox': 765, 'n_words': 170}