<commit_before>import os
import pytest
from collections import OrderedDict
from encoded.commands import generate_ontology as go
pytestmark = pytest.mark.working


def test_parse_args_defaults():
    args = ''
    args = go.parse_args(args)
    assert args.ontologies == 'all'
    assert args.keyfile == os.path.expanduser('~/keypairs.json')
    assert args.key == 'default'


@pytest.fixture
def slim_terms():
    return [
        {
            "uuid": "111119bc-8535-4448-903e-854af460a233",
            "term_name": "ectoderm",
            "term_id": "UBERON:0000924",
            "is_slim_for": "developmental",
        },
        {
            "uuid": "111122bc-8535-4448-903e-854af460a233",
            "preferred_name": "3D chromatin structure",
            "term_name": "chromosome conformation identification objective",
            "term_id": "OBI:0001917",
            "is_slim_for": "assay"
        }
    ]


@pytest.fixture
def connection(mocker):
    return mocker.patch.object(go, 'FDN_Connection')


def test_connect2server(mocker):
    # mock submit4dn stuff
    mocker.patch.object(go, 'FDN_Key')
    mocker.patch.object(go, 'FDN_Connection')
    go.FDN_Connection.server.return_value = 'test_server'
    go.FDN_Connection.check.return_value = True

    # run the test, we mocked everything so
    # parameters we pass in don't really matter
    retval = go.connect2server('dummy-keyfile', 'dummy-keyname')
    assert retval is not None


# see ontology schema for full schema
# now synonym_terms and definition_terms are fully embedded
all_ontology = [{'download_url': 'http://www.ebi.ac.uk/efo/efo_inferred.owl',
                 'synonym_terms': [
                     '/ontology-terms/111111bc-8535-4448-903e-854af460a233/',
                     '/ontology-terms/111112bc-8535-4448-903e-854af460a233/'],
                 '@id': '/ontologys/530006bc-8535-4448-903e-854af460b254/',
                 '@type': ['Ontology', 'Item'],
                 'definition_terms': [
                     '/ontology-terms/111115bc-8535-4448-903e-854af460a233/',
                     '/ontology-terms/111116bc-8535-4448-903e-854af460a233/'],
                 'namespace_url': 'http://www.ebi.ac.uk/efo/',
                 'ontology_prefix': 'EFO',
                 'uuid': '530006bc-8535-4448-903e-854af460b254',
                 'ontology_name': 'Experimental Factor Ontology'
                 },
                 {'ontology_name': 'Uberon',
                 '@type': ['Ontology', 'Item'],
                 'ontology_prefix': 'UBERON',
                 'namespace_url': 'http://purl.obolibrary.org/obo/',
                 'download_url': 'http://purl.obolibrary.org/obo/uberon/composite-metazoan.owl',
                 '@id': '/ontologys/530016bc-8535-4448-903e-854af460b254/',
                 'definition_terms': ['/ontology-terms/111116bc-8535-4448-903e-854af460a233/'],
                 'uuid': '530016bc-8535-4448-903e-854af460b254',
                 },
                 {'ontology_name': 'Ontology for Biomedical Investigations',
                 '@type': ['Ontology', 'Item'],
                 'ontology_prefix': 'OBI',
                 'namespace_url': 'http://purl.obolibrary.org/obo/',
                 'download_url': 'http://purl.obolibrary.org/obo/obi.owl',
                 '@id': '/ontologys/530026bc-8535-4448-903e-854af460b254/',
                 'definition_terms': [
                     {'term_name': 'definition',
                      '@type': ['OntologyTerm', 'Item'],
                      'term_id': 'IAO:0000115',
                      '@id': '/ontology-terms/111116bc-8535-4448-903e-854af460a233/',
                      'uuid': '111116bc-8535-4448-903e-854af460a233',
                      'term_url': 'http://purl.obolibrary.org/obo/IAO_0000115'
                     }
                  ],
                 'uuid': '530026bc-8535-4448-903e-854af460b254',
                 'synonym_terms': [
                    {'term_name': 'alternative term',
                     '@type': ['OntologyTerm', 'Item'],
                     'term_id': 'IAO:0000118',
                     '@id': '/ontology-terms/111117bc-8535-4448-903e-854af460a233/',
                     'uuid': '111117bc-8535-4448-903e-854af460a233',
                     'term_url': 'http://purl.obolibrary.org/obo/IAO_0000118'
                    },
                    {'term_name': 'alternative term',
                     '@type': ['OntologyTerm', 'Item'],
                     'term_id': 'IAO:0000118',
                     '@id': '/ontology-terms/111117bc-8535-4448-903e-854af460a233/',
                     'uuid': '111117bc-8535-4448-903e-854af460a233',
                     'term_url': 'http://purl.obolibrary.org/obo/IAO_0000118'
                    }
                   ]
                  }]


def get_fdn_ontology_side_effect(*args):
    for i, arg in enumerate(args):
        print('ARG', i, ' = ', arg)
    if args[0] is not None:
        return all_ontology[0]
    else:
        return all_ontology


def test_get_ontologies_all(mocker, connection):
    prefixes = ['EFO', 'UBERON', 'OBI']
    with mocker.patch('encoded.commands.generate_ontology.get_FDN', side_effect=get_fdn_ontology_side_effect):
        ont_list = 'all'
        ontologies = go.get_ontologies(connection, ont_list)
        assert len(ontologies) == 3
        for ont in ontologies:
            assert ont['ontology_prefix'] in prefixes

<commit_msg>FF-576 #comment small tweak to a test fixture<commit_after>import os
import pytest
from collections import OrderedDict
from encoded.commands import generate_ontology as go
pytestmark = pytest.mark.working


def test_parse_args_defaults():
    args = ''
    args = go.parse_args(args)
    assert args.ontologies == 'all'
    assert args.keyfile == os.path.expanduser('~/keypairs.json')
    assert args.key == 'default'


@pytest.fixture
def slim_terms():
    return [
        {
            "uuid": "111119bc-8535-4448-903e-854af460a233",
            "term_name": "ectoderm",
            "term_id": "UBERON:0000924",
            "is_slim_for": "developmental",
        },
        {
            "uuid": "111122bc-8535-4448-903e-854af460a233",
            "preferred_name": "3D chromatin structure",
            "term_name": "chromosome conformation identification objective",
            "term_id": "OBI:0001917",
            "is_slim_for": "assay"
        }
    ]


@pytest.fixture
def connection(mocker):
    return mocker.patch.object(go, 'FDN_Connection')


def test_connect2server(mocker):
    # mock submit4dn stuff
    mocker.patch.object(go, 'FDN_Key')
    mocker.patch.object(go, 'FDN_Connection')
    go.FDN_Connection.server.return_value = 'test_server'
    go.FDN_Connection.check.return_value = True

    # run the test, we mocked everything so
    # parameters we pass in don't really matter
    retval = go.connect2server('dummy-keyfile', 'dummy-keyname')
    assert retval is not None


# see ontology schema for full schema
# now synonym_terms and definition_terms are fully embedded
all_ontology = [{'download_url': 'http://www.ebi.ac.uk/efo/efo_inferred.owl',
                 'synonym_terms': [
                     '/ontology-terms/111111bc-8535-4448-903e-854af460a233/',
                     '/ontology-terms/111112bc-8535-4448-903e-854af460a233/'],
                 '@id': '/ontologys/530006bc-8535-4448-903e-854af460b254/',
                 '@type': ['Ontology', 'Item'],
                 'definition_terms': [
                     '/ontology-terms/111115bc-8535-4448-903e-854af460a233/',
                     '/ontology-terms/111116bc-8535-4448-903e-854af460a233/'],
                 'namespace_url': 'http://www.ebi.ac.uk/efo/',
                 'ontology_prefix': 'EFO',
                 'uuid': '530006bc-8535-4448-903e-854af460b254',
                 'ontology_name': 'Experimental Factor Ontology'
                 },
                 {'ontology_name': 'Uberon',
                 '@type': ['Ontology', 'Item'],
                 'ontology_prefix': 'UBERON',
                 'namespace_url': 'http://purl.obolibrary.org/obo/',
                 'download_url': 'http://purl.obolibrary.org/obo/uberon/composite-metazoan.owl',
                 '@id': '/ontologys/530016bc-8535-4448-903e-854af460b254/',
                 'definition_terms': ['/ontology-terms/111116bc-8535-4448-903e-854af460a233/'],
                 'uuid': '530016bc-8535-4448-903e-854af460b254',
                 },
                 {'ontology_name': 'Ontology for Biomedical Investigations',
                 '@type': ['Ontology', 'Item'],
                 'ontology_prefix': 'OBI',
                 'namespace_url': 'http://purl.obolibrary.org/obo/',
                 'download_url': 'http://purl.obolibrary.org/obo/obi.owl',
                 '@id': '/ontologys/530026bc-8535-4448-903e-854af460b254/',
                 'definition_terms': [
                     {'term_name': 'definition',
                      '@type': ['OntologyTerm', 'Item'],
                      'term_id': 'IAO:0000115',
                      '@id': '/ontology-terms/111116bc-8535-4448-903e-854af460a233/',
                      'uuid': '111116bc-8535-4448-903e-854af460a233',
                      'term_url': 'http://purl.obolibrary.org/obo/IAO_0000115'
                     }
                  ],
                 'uuid': '530026bc-8535-4448-903e-854af460b254',
                 'synonym_terms': [
                    {'term_name': 'alternative term',
                     '@type': ['OntologyTerm', 'Item'],
                     'term_id': 'IAO:0000118',
                     '@id': '/ontology-terms/111117bc-8535-4448-903e-854af460a233/',
                     'uuid': '111117bc-8535-4448-903e-854af460a233',
                     'term_url': 'http://purl.obolibrary.org/obo/IAO_0000118'
                    },
                    {'term_name': 'alternative term',
                     '@type': ['OntologyTerm', 'Item'],
                     'term_id': 'IAO:0000118',
                     '@id': '/ontology-terms/111117bc-8535-4448-903e-854af460a233/',
                     'uuid': '111117bc-8535-4448-903e-854af460a233',
                     'term_url': 'http://purl.obolibrary.org/obo/IAO_0000118'
                    }
                   ]
                  }]


def get_fdn_ontology_side_effect(*args, **kwargs):
    for i, arg in enumerate(args):
        print('ARG', i, ' = ', arg)
    if args[0] is not None:
        return all_ontology[0]
    else:
        return all_ontology


def test_get_ontologies_all(mocker, connection):
    prefixes = ['EFO', 'UBERON', 'OBI']
    with mocker.patch('encoded.commands.generate_ontology.get_FDN', side_effect=get_fdn_ontology_side_effect):
        ont_list = 'all'
        ontologies = go.get_ontologies(connection, ont_list)
        assert len(ontologies) == 3
        for ont in ontologies:
            assert ont['ontology_prefix'] in prefixes


{'fraction_non_alphanumeric': 0.13843468675362852, 'fraction_numerical': 0.10260885541061915, 'mean_word_length': 1.9140792291220556, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2756154', 'n_tokens_mistral': 4291, 'n_tokens_neox': 3488, 'n_words': 526}