Commit d3406a7d authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

flake8 tests

parent b3d82cdf3d87
......@@ -27,4 +27,3 @@ class language_to(RelationDefinition):
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CS scheme_relation_type CR, '
'CR name "language_to"')]
......@@ -128,21 +128,24 @@ class ConceptSchemeTC(testlib.CubicWebTC):
with open(csv_file) as sourcefile:
scheme.add_concepts_from_file(sourcefile, u'utf-8', u'fr', u'\t')
result = build_result_dict(scheme)
expected = {u'APPELLATION DES LOIS ET DES RAPPORTS':
{u'LOIS RAPPORTS JURISPRUDENCE':
{u'APPELLATION DE DECISIONS DE JURISPRUDENCE':
{u'ARRET BERKANI': {}, u'ARRET TERNON': {}},
u'APPELLATION DES RAPPORTS':
{u'RAPPORT ARTHUIS': {}, u'LOLF': {}, u'LOV': {}}
}
expected = {
u'APPELLATION DES LOIS ET DES RAPPORTS': {
u'LOIS RAPPORTS JURISPRUDENCE': {
u'APPELLATION DE DECISIONS DE JURISPRUDENCE': {
u'ARRET BERKANI': {}, u'ARRET TERNON': {},
},
u'LISTE DES MOTS OUTILS':
{u'CHAPITRE MOTS OUTILS':
{u'MOTS OUTILS':
{u'ABATTEMENT': {}, u'ACCORD': {}}
}
u'APPELLATION DES RAPPORTS': {
u'RAPPORT ARTHUIS': {}, u'LOLF': {}, u'LOV': {}},
}
},
u'LISTE DES MOTS OUTILS': {
u'CHAPITRE MOTS OUTILS': {
u'MOTS OUTILS': {
u'ABATTEMENT': {}, u'ACCORD': {},
}
}
}
}
}
self.assertEqual(result, expected)
def test_add_concepts_from_file_sep_inside_concept(self):
......@@ -155,7 +158,7 @@ class ConceptSchemeTC(testlib.CubicWebTC):
scheme.add_concepts_from_file(rapport, u'utf-8', u'fr', u'\t')
result = build_result_dict(scheme)
expected = {u'toto': {u'ti\tti': {},
u'tata' : {}}}
u'tata': {}}}
self.assertEqual(result, expected)
def test_add_concepts_from_file_decode_error(self):
......@@ -344,7 +347,7 @@ class RDFAdaptersTC(testlib.CubicWebTC):
(concept.absolute_url(), TYPE_PREDICATE_URI, SKOS_CONCEPT),
(concept.absolute_url(), SKOS_DEFINITION, u'def1'),
(concept.absolute_url(), SKOS_INSCHEME, scheme.absolute_url()),
]
]
self.assertCountEqual(set(graph.triples()), expected)
test_rdflib_concept_list_repr = require_lib('rdflib')(_test_concept_list_repr)
......
......@@ -42,44 +42,44 @@ class LCSV2RDFTC(TestCase):
lcsv2rdf = lcsv.LCSV2RDF(open(fpath), '\t', 'utf-8',
uri_generator=lambda x: x, default_lang='es')
self.assertEqual(set(list(lcsv2rdf.triples())),
set([('#1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#1', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Définition de l'organisation politique de l'organisme,", 'fr')),
('#1', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Vie politique", 'es')),
('#2', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#2', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Définition (évolution) des règles de fonctionnement", 'fr')),
('#2', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Assemblée délibérante", 'es')),
('#2', 'http://www.w3.org/2004/02/skos/core#broader',
'#1'),
('#3', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#3', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Création volontaire ou en application de la loi", 'fr')),
('#3', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Instances consultatives", 'es')),
('#3', 'http://www.w3.org/2004/02/skos/core#broader',
'#1'),
('#4', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#4', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Fonction de définition d'objectifs à long terme", 'fr')),
('#4', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Pilotage de l'organisation", 'es')),
('#5', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#5', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Définition du projet d'administration", 'fr')),
('#5', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Pilotage de Bordeaux Metropole", 'es')),
('#5', 'http://www.w3.org/2004/02/skos/core#broader',
'#4')
])
)
set([
('#1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#1', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Définition de l'organisation politique de l'organisme,", 'fr')),
('#1', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Vie politique", 'es')),
('#2', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#2', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Définition (évolution) des règles de fonctionnement", 'fr')),
('#2', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Assemblée délibérante", 'es')),
('#2', 'http://www.w3.org/2004/02/skos/core#broader',
'#1'),
('#3', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#3', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Création volontaire ou en application de la loi", 'fr')),
('#3', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Instances consultatives", 'es')),
('#3', 'http://www.w3.org/2004/02/skos/core#broader',
'#1'),
('#4', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#4', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Fonction de définition d'objectifs à long terme", 'fr')),
('#4', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Pilotage de l'organisation", 'es')),
('#5', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
'http://www.w3.org/2004/02/skos/core#Concept'),
('#5', 'http://www.w3.org/2004/02/skos/core#definition',
ul(u"Définition du projet d'administration", 'fr')),
('#5', 'http://www.w3.org/2004/02/skos/core#prefLabel',
ul(u"Pilotage de Bordeaux Metropole", 'es')),
('#5', 'http://www.w3.org/2004/02/skos/core#broader',
'#4')
]))
if __name__ == "__main__":
from unittest import main
......
......@@ -210,7 +210,8 @@ class RDFGraphTCMixIn(object):
('http://example.org/people/Bob', 'http://foaf.com/firstname', u'bob'),
('http://example.org/people/Bob', 'http://foaf.com/age', 45),
('http://example.org/people/Bob', 'http://dc.com/description', ul('man', 'en')),
('http://example.org/people/Bob', 'http://foaf.com/knows', 'http://example.org/people/Alice'),
('http://example.org/people/Bob', 'http://foaf.com/knows',
'http://example.org/people/Alice'),
])
def test_add(self):
......@@ -229,8 +230,8 @@ class RDFGraphTCMixIn(object):
self.assertTrue(self._triples.issubset(triples))
def test_load_dump_roundtrip(self):
for rdf_format in ('xml',): # 'n3', 'nt'): XXX other formats fail, but sounds due to the
# underlying lib
# XXX other formats fail, but sounds due to the underlying lib
for rdf_format in ('xml',): # 'n3', 'nt'):
self.set_description('testing roundtrip for the %s format' % rdf_format)
self.assertRoundTrip(rdf_format)
......@@ -300,7 +301,8 @@ class RDFGraphToEntitiesTC(TestCase):
ext_entities = rdfio.rdf_graph_to_entities(xy, graph, etypes)
e = ext_entities_to_dict(ext_entities)
self.assertEqual(e['ConceptScheme'][dcf('Matiere')],
{'title': set([u"Thésaurus-matières pour l'indexation des archives locales"])})
{'title': set([u"Thésaurus-matières pour l'indexation "
"des archives locales"])})
self.assertEqual(e['Concept'][dcf('T1-1073')],
{'broader_concept': set([dcf('T1-3')]),
'in_scheme': set([dcf('Matiere')]),
......
......@@ -71,11 +71,15 @@ class SKOSXMLImportTC(testlib.CubicWebTC):
def check_siaf_shortened(self, source_name):
with self.admin_access.client_cnx() as cnx:
scheme = cnx.find('ConceptScheme', cwuri='http://data.culture.fr/thesaurus/resource/ark:/67717/Matiere').one()
self.assertEqual(scheme.title, u"Thésaurus-matières pour l'indexation des archives locales")
self.assertEqual(scheme.description, u"""Le Thésaurus pour la description et l'indexation des archives locales s'applique à tous les fonds d'archives locales, publiques et privées, anciennes, modernes et contemporaines. Il a valeur réglementaire pour l’ensemble des services d’archives territoriales – régionales, départementales et communales. Il se compose du thésaurus-matières, essentiellement réservé aux expressions illustrant la notion d'objet mais accueillant aussi des termes liés à des attributions essentielles des producteurs d'archives (par exemple : police, fiscalité, aide sociale), ainsi que trois listes d'autorité ("Actions", "Typologie documentaire", "Contexte historique") contenant des descripteurs qui ne sont pas par eux-mêmes des termes d'indexation mais qu'on associera à un ou plusieurs descripteurs du thésaurus, si le contexte documentaire l'exige.""")
scheme = cnx.find('ConceptScheme', cwuri='http://data.culture.fr/'
'thesaurus/resource/ark:/67717/Matiere').one()
self.assertEqual(scheme.title, u"Thésaurus-matières pour "
"l'indexation des archives locales")
descr = u"Le Thésaurus pour la description et l'indexation des archives locales"
self.assertEqual(scheme.description[:len(descr)], descr)
self.assertEqual(scheme.description_format, u"text/plain")
self.assertEqual(scheme.cwuri, u'http://data.culture.fr/thesaurus/resource/ark:/67717/Matiere')
self.assertEqual(scheme.cwuri, u'http://data.culture.fr/'
'thesaurus/resource/ark:/67717/Matiere')
self.assertEqual(scheme.cw_source[0].name, source_name)
top_concepts = dict((c.cwuri, c) for c in scheme.top_concepts)
# 11 original top concepts + 1 because of missing broader concept
......@@ -89,42 +93,52 @@ class SKOSXMLImportTC(testlib.CubicWebTC):
self.assertEqual(len(narrow_concepts), 2)
label = concept.preferred_label[0]
# XXX support skos-xl
self.assertEqual(label.cwuri, u'http://data.culture.fr/thesaurus/resource/ark:/67717/T1-503#preferred_label8c179857731ea1dbfc9d152ba4338eda')
self.assertEqual(label.cwuri, u'http://data.culture.fr/thesaurus/resource/'
'ark:/67717/T1-503#preferred_label8c179857731ea1dbfc9d152ba4338eda')
self.assertEqual(label.cw_source[0].name, source_name)
self.assertEqual(label.label, u'communications')
self.failIf(cnx.execute('Any L WHERE NOT EXISTS(L label_of X)'))
# exact / close match
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/ark:/67717/T1-246').one()
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/'
'ark:/67717/T1-246').one()
self.assertEqual(len(concept.exact_match), 1)
self.assertEqual(concept.exact_match[0].cw_etype, 'Concept')
self.assertEqual(concept.exact_match[0].cwuri, 'http://data.bnf.fr/ark:/12148/cb11934798x')
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/ark:/67717/T1-1317').one()
self.assertEqual(concept.exact_match[0].cwuri,
'http://data.bnf.fr/ark:/12148/cb11934798x')
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/'
'ark:/67717/T1-1317').one()
self.assertEqual(len(concept.exact_match), 1)
exturi = concept.exact_match[0]
self.assertEqual(exturi.cw_etype, 'ExternalUri')
self.assertEqual(exturi.cwuri, 'http://data.bnf.fr/ark:/12148/cb120423190')
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/ark:/67717/T1-543').one()
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/'
'ark:/67717/T1-543').one()
self.assertEqual(len(concept.close_match), 1)
self.assertEqual(concept.close_match[0].cw_etype, 'ExternalUri')
self.assertEqual(concept.close_match[0].uri, 'http://dbpedia.org/resource/Category:Economics')
self.assertEqual(concept.close_match[0].uri,
'http://dbpedia.org/resource/Category:Economics')
# full-text indexation
rset = cnx.execute('Any U WHERE X cwuri U, X has_text %(q)s', {'q': 'communications'})
self.assertEqual(rset.rows, [['http://data.culture.fr/thesaurus/resource/ark:/67717/T1-503']])
self.assertEqual(rset.rows,
[['http://data.culture.fr/thesaurus/resource/ark:/67717/T1-503']])
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/ark:/67717/T1-246').one()
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/'
'ark:/67717/T1-246').one()
exturi.cw_set(inlined_match=concept)
cnx.commit()
self.pull_source('rameau')
with self.admin_access.client_cnx() as cnx:
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/ark:/67717/T1-1317').one()
concept = cnx.find('Concept', cwuri='http://data.culture.fr/thesaurus/resource/'
'ark:/67717/T1-1317').one()
self.assertEqual(concept.label(), 'administration')
self.assertEqual(len(concept.exact_match), 1)
former_exturi = concept.exact_match[0]
self.assertEqual(former_exturi.cw_etype, 'Concept')
self.assertEqual(former_exturi.cwuri, 'http://data.bnf.fr/ark:/12148/cb120423190')
self.assertEqual(former_exturi.inlined_match[0].cwuri, 'http://data.culture.fr/thesaurus/resource/ark:/67717/T1-246')
self.assertEqual(former_exturi.inlined_match[0].cwuri,
'http://data.culture.fr/thesaurus/resource/ark:/67717/T1-246')
def test_datafeed_source(self):
# test creation upon initial pull
......@@ -135,10 +149,12 @@ class SKOSXMLImportTC(testlib.CubicWebTC):
def test_service(self):
with self.admin_access.repo_cnx() as cnx:
scheme_uris = cnx.call_service('rdf.skos.import',
stream=open(self.datapath('siaf_matieres_shortened.xml')),
rdf_format='xml')[-1]
self.assertEqual(scheme_uris, ['http://data.culture.fr/thesaurus/resource/ark:/67717/Matiere'])
scheme_uris = cnx.call_service(
'rdf.skos.import',
stream=open(self.datapath('siaf_matieres_shortened.xml')),
rdf_format='xml')[-1]
self.assertEqual(scheme_uris,
['http://data.culture.fr/thesaurus/resource/ark:/67717/Matiere'])
self.check_siaf_shortened(u'system')
def test_oddities(self):
......@@ -146,12 +162,14 @@ class SKOSXMLImportTC(testlib.CubicWebTC):
cnx.call_service('rdf.skos.import',
stream=open(self.datapath('oddities.xml')),
rdf_format='xml')
scheme = cnx.execute('ConceptScheme X WHERE X cwuri "http://data.culture.fr/thesaurus/Matiere"').one()
scheme = cnx.execute('ConceptScheme X WHERE '
'X cwuri "http://data.culture.fr/thesaurus/Matiere"').one()
self.assertEqual(scheme.dc_title(), scheme.cwuri)
concept = scheme.reverse_in_scheme[0]
self.assertEqual(concept.label(), u'communications')
self.assertEqual(len(concept.in_scheme), 2)
concept = cnx.execute('Concept X WHERE X cwuri "http://logilab.fr/thesaurus/test/c3"').one()
concept = cnx.execute('Concept X WHERE '
'X cwuri "http://logilab.fr/thesaurus/test/c3"').one()
self.assertEqual(len(concept.broader_concept), 2)
......@@ -182,9 +200,8 @@ class LCSVImportTC(testlib.CubicWebTC):
self.assertEqual(len(scheme.top_concepts), 2)
concepts = cnx.find('Concept')
self.assertEqual(len(concepts), 5)
concept1 = cnx.find('Concept',
definition=u"Définition de l'organisation politique de l'organisme,"
).one()
concept1 = cnx.find(
'Concept', definition=u"Définition de l'organisation politique de l'organisme,").one()
label = concept1.preferred_label[0]
self.assertEqual(label.label, "Vie politique")
self.assertEqual(len(concept1.preferred_label), 1)
......
......@@ -43,13 +43,14 @@ class ViewsTC(testlib.CubicWebTC):
'language_code': u'fr',
'format': u'simple',
'delimiter': u'tab',
}, [(scheme, {})])
}, [(scheme, {})])
# now actually tests the import, using scheme.view and not self.view which doesn't like
# exception, even Redirect
self.assertRaises(Redirect, scheme.view, 'skos.scheme.import')
self.assertEqual(set(c.dc_title() for c in scheme.top_concepts),
set(u'électro hip-hop rap jazz classique'.split()))
self.assertEqual(set(l.language_code for c in scheme.top_concepts for l in c.preferred_label),
self.assertEqual(set(l.language_code for c in scheme.top_concepts
for l in c.preferred_label),
set(['fr']))
def test_lcsv_scheme_concepts_import(self):
......
......@@ -31,7 +31,7 @@ commands =
[flake8]
max-line-length = 100
exclude = test,migration,__pkginfo__.py,setup.py,.tox
exclude = migration,__pkginfo__.py,setup.py,.tox
ignore = E731,W503
[pytest]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment