Skip to content

Commit

Permalink
fixed problems with test
Browse files Browse the repository at this point in the history
  • Loading branch information
inflector committed Oct 24, 2017
1 parent 15d2b25 commit f477f66
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 11 deletions.
33 changes: 33 additions & 0 deletions agent/demo/tensorflow_mnist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# entity_extracter/__init__.py - demo agent service adapter...
#
# Copyright (c) 2017 SingularityNET
#
# Distributed under the MIT software license, see LICENSE file.
#

from typing import List

from sn_agent.job.job_descriptor import JobDescriptor
from sn_agent.service_adapter.base import ModuleServiceAdapterABC

import logging

log = logging.getLogger(__name__)

class EntityExtracter(ModuleServiceAdapterABC):
type_name = "EntityExtracter"

def __init__(self, app, service_ontology_node, required_service_nodes, name: str):
super().__init__(app, service_ontology_node, required_service_nodes, name)

def perform(self, job: JobDescriptor):
item_count = 0
for job_item in job:
file_name = job[item_count]['output_url']
with open(file_name, 'w') as file:
file.write("entity:\n")
file.write(" pig\n")
file.write(" farmer\n")
file.write(" tractor\n")
file.write(" cornfield\n")
10 changes: 8 additions & 2 deletions agent/sn_agent/job/job_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
# Distributed under the MIT software license, see LICENSE file.
#

from typing import List

from sn_agent import ontology
from sn_agent.ontology.service_descriptor import ServiceDescriptor

test_jobs = {}


class JobDescriptor(object):
def __init__(self, service: ServiceDescriptor, job_parameters: list = None):
def __init__(self, service: ServiceDescriptor, job_parameters: List[dict] = None):
self.service = service

if job_parameters is None:
Expand Down Expand Up @@ -80,27 +82,31 @@ def init_test_jobs():
}
]

#TODO: These need to be fixed so that we can test for single and multiple jobs
# Create test jobs for the document summarizer.
service_id = ontology.DOCUMENT_SUMMARIZER_ID
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters)
test_jobs[service_id].append(job)
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters_2)
test_jobs[service_id].append(job)

# Create test jobs for the word-sense disambiguator.
service_id = ontology.WORD_SENSE_DISAMBIGUATER_ID
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters)
test_jobs[service_id].append(job)
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters_2)
test_jobs[service_id].append(job)

# Create test jobs for the face recognizer.
service_id = ontology.FACE_RECOGNIZER_ID
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters)
test_jobs[service_id].append(job)

# Create test jobs for the text summarizer.
service_id = ontology.TEXT_SUMMARIZER_ID
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters)
test_jobs[service_id].append(job)

# Create test jobs for the entity extractor.
service_id = ontology.ENTITY_EXTRACTER_ID
job = JobDescriptor(ServiceDescriptor(service_id), job_parameters)
test_jobs[service_id].append(job)
3 changes: 3 additions & 0 deletions agent/sn_agent/service_adapter/external_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#

import jsonrpcclient
import logging

from sn_agent.job.job_descriptor import JobDescriptor
from sn_agent.ontology import Service
from sn_agent.service_adapter.base import ServiceAdapterABC

logger = logging.getLogger(__name__)

class ExternalServiceAdapter(ServiceAdapterABC):
def __init__(self, app, agent_id, service: Service):
Expand All @@ -31,6 +33,7 @@ def __init__(self, app, agent_id, service: Service):
network = self.app['network']
# This is a hack, we should never really get more than 1 URL per agent
agent_urls = network.dht.get(agent_id)
logger.debug("agent_urls for {0} = {1}".format(agent_id, agent_urls))
self.agent_url = agent_urls[0]['url']

def has_all_requirements(self):
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions agent/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ def test_jobs():
service_id = ontology.DOCUMENT_SUMMARIZER_ID

# Create a new job descriptor with four sets of parameters.
new_job = JobDescriptor(ServiceDescriptor(service_id), job_parameters)
new_job.append_job_item(job_parameters)
new_job.append_job_item(job_parameters)
new_job.append_job_item(job_parameters)
job_list = [job_parameters, job_parameters, job_parameters, job_parameters]
new_job = JobDescriptor(ServiceDescriptor(service_id), job_list)

file_count = 0
for job_item in new_job:
if job_item['input_type'] == 'file':
Expand All @@ -66,6 +65,6 @@ def test_jobs():
del test_jobs[total_jobs-1]

# Check the string conversion with no ServiceDescriptor...
new_job = JobDescriptor(None, job_parameters)
new_job = JobDescriptor(None, [job_parameters])
assert(str(new_job) != "")

16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ services:
volumes:
- ./agent-data:/data

test:
build: agent
environment:
- SN_AGENT_ID=b545478a-971a-48ec-bc56-4b9b7176799c
- SN_NETWORK_WEB_PORT=8000
- SN_SERVICE_ADAPTER_CONFIG_FILE=test_config.yml
- PYTHONPATH=/code
- SN_DS_TEST_OUTPUT_DIRECTORY=/data
ports:
- "8000:8000"
volumes:
- ./agent-data:/data
links:
- testrpc


agent-web:
build: agent-web
ports:
Expand Down
8 changes: 4 additions & 4 deletions tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ bob)
;;

agent-docs)
recreate_agent_image
docker-compose run agent ./agent.sh docs
docker-compose create --build --force-recreate test
docker-compose run test ./agent.sh docs
;;

agent-test)
recreate_agent_image
docker-compose run agent ./agent.sh test
docker-compose create --build --force-recreate test
docker-compose run test ./agent.sh test
;;

agent-web)
Expand Down

0 comments on commit f477f66

Please sign in to comment.