-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adiciona a classe FundingGroup * Adiciona teste para caso em que há 1 found_source e n award_ids * Adiciona teste para caso em que há 1 found_source e 1 award_id * Adiciona teste para caso em que há n found_sources e 1 award_ids * Adiciona teste para caso em que há n found_sources e 1 award_id
- Loading branch information
1 parent
e1bd9ff
commit 5fb56cd
Showing
2 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
|
||
from packtools.sps.utils import xml_utils | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class FundingGroup: | ||
""" | ||
Class that performs the extraction of values for funding-source and award-id. | ||
To return both attributes, award_groups is used. | ||
To return only institutions, use funding_sources. | ||
Parameters | ||
---------- | ||
xml | ||
XML file that contains the attributes of interest. | ||
Returns | ||
------- | ||
list | ||
Arrangement containing a dictionary that correlates funding-source and award-id or values of one of the attributes. | ||
""" | ||
|
||
def __init__(self, xml): | ||
self._xmltree = xml_utils.get_xml_tree(xml) | ||
|
||
@property | ||
def award_groups(self): | ||
items = [] | ||
for node in self._xmltree.xpath(".//funding-group/award-group"): | ||
funding_sources = node.xpath("funding-source") | ||
award_ids = node.xpath("award-id") | ||
d = {} | ||
d["funding-source"] = [item.text for item in funding_sources] | ||
d["award-id"] = [item.text for item in award_ids] | ||
items.append(d) | ||
return items | ||
|
||
@property | ||
def funding_sources(self): | ||
items = [] | ||
for node in self._xmltree.xpath(".//funding-group/award-group/funding-source"): | ||
items.append(node.text) | ||
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# coding: utf-8 | ||
from __future__ import unicode_literals | ||
import unittest | ||
|
||
try: | ||
from unittest import mock | ||
except: | ||
import mock | ||
|
||
from packtools.sps.models.funding_group import FundingGroup | ||
|
||
|
||
class FundingGroupOneFundingSourceNAwardIdTests(unittest.TestCase): | ||
def setUp(self): | ||
xml = ( | ||
""" | ||
<article> | ||
<funding-group> | ||
<award-group> | ||
<funding-source>CNPQ</funding-source> | ||
<award-id>12345</award-id> | ||
<award-id>67890</award-id> | ||
</award-group> | ||
<award-group> | ||
<funding-source>FAPESP</funding-source> | ||
<award-id>23456</award-id> | ||
<award-id>56789</award-id> | ||
</award-group> | ||
</funding-group> | ||
</article> | ||
""" | ||
) | ||
self.funding_group = FundingGroup(xml) | ||
|
||
def test_funding_sources(self): | ||
expected = ['CNPQ', 'FAPESP'] | ||
result = self.funding_group.funding_sources | ||
self.assertEqual(expected, result) | ||
|
||
def test_award_groups(self): | ||
expected = [ | ||
{'funding-source': ['CNPQ'], 'award-id': ['12345', '67890']}, | ||
{'funding-source': ['FAPESP'], 'award-id': ['23456', '56789']}, | ||
] | ||
result = self.funding_group.award_groups | ||
self.assertEqual(expected, result) | ||
|
||
|
||
class FundingGroupOneFundingSourceOneAwardIdTests(unittest.TestCase): | ||
def setUp(self): | ||
xml = ( | ||
""" | ||
<article> | ||
<funding-group> | ||
<award-group> | ||
<funding-source>CNPq</funding-source> | ||
<award-id>1685X6-7</award-id> | ||
</award-group> | ||
</funding-group> | ||
</article> | ||
""" | ||
) | ||
self.funding_group = FundingGroup(xml) | ||
|
||
def test_funding_sources(self): | ||
expected = ['CNPq'] | ||
result = self.funding_group.funding_sources | ||
self.assertEqual(expected, result) | ||
|
||
def test_award_groups(self): | ||
expected = [ | ||
{'funding-source': ['CNPq'], 'award-id': ['1685X6-7']} | ||
] | ||
result = self.funding_group.award_groups | ||
self.assertEqual(expected, result) | ||
|
||
|
||
class FundingGroupNFundingSourceOneAwardIdTests(unittest.TestCase): | ||
def setUp(self): | ||
xml = ( | ||
""" | ||
<article> | ||
<funding-group> | ||
<award-group> | ||
<funding-source>CNPq</funding-source> | ||
<funding-source>FAPESP</funding-source> | ||
<award-id>#09/06953-4</award-id> | ||
</award-group> | ||
</funding-group> | ||
</article> | ||
""" | ||
) | ||
self.funding_group = FundingGroup(xml) | ||
|
||
def test_funding_sources(self): | ||
expected = ['CNPq', 'FAPESP'] | ||
result = self.funding_group.funding_sources | ||
self.assertEqual(expected, result) | ||
|
||
def test_award_groups(self): | ||
expected = [ | ||
{'funding-source': ['CNPq', 'FAPESP'], 'award-id': ['#09/06953-4']} | ||
] | ||
result = self.funding_group.award_groups | ||
self.assertEqual(expected, result) | ||
|
||
|
||
class FundingGroupNFundingSourceOneAwardIdWithFundingStatementTests(unittest.TestCase): | ||
def setUp(self): | ||
xml = ( | ||
""" | ||
<article> | ||
<funding-group> | ||
<award-group> | ||
<funding-source>Coordenação de Aperfeiçoamento de Pessoal de Nível Superior</funding-source> | ||
<funding-source> Fundação de Amparo à Pesquisa do Estado de São Paulo</funding-source> | ||
<award-id>04/08142-0</award-id> | ||
</award-group> | ||
<funding-statement>This study was supported in part by Coordenação | ||
de Aperfeiçoamento de Pessoal de Nível Superior (Capes — Brasília, | ||
Brazil), Fundação de Amparo à Pesquisa do Estado de São Paulo (FAPESP — | ||
Grant no. 04/08142-0; São Paulo, Brazil)</funding-statement> | ||
</funding-group> | ||
</article> | ||
""" | ||
) | ||
self.funding_group = FundingGroup(xml) | ||
|
||
def test_funding_sources(self): | ||
expected = ['Coordenação de Aperfeiçoamento de Pessoal de Nível Superior', | ||
' Fundação de Amparo à Pesquisa do Estado de São Paulo'] | ||
result = self.funding_group.funding_sources | ||
self.assertEqual(expected, result) | ||
|
||
def test_award_groups(self): | ||
expected = [ | ||
{'funding-source': ['Coordenação de Aperfeiçoamento de Pessoal de Nível Superior', | ||
' Fundação de Amparo à Pesquisa do Estado de São Paulo'], 'award-id': ['04/08142-0']} | ||
] | ||
result = self.funding_group.award_groups | ||
self.assertEqual(expected, result) |