<commit_before>#!/usr/bin/env python

"""
@package ion.agents.platform.cgsn.test.test_cgsn_client
@file    ion/agents/platform/cgsn/test/test_cgsn_client.py
@author  <NAME>
@brief   preliminary tests
"""

__author__ = '<NAME>'
__license__ = 'Apache 2.0'


from pyon.public import log
from pyon.util.unit_test import IonUnitTestCase

from gevent import sleep

from ion.agents.platform.cgsn.cgsn_client_factory import CgsnClientFactory
from ion.agents.platform.cgsn.cgsn_state import CgsnState
from ion.agents.platform.cgsn.defs import DclIds, MessageIds


class Test(IonUnitTestCase):

    def setUp(self):
        self._cgsn_state = CgsnState()
        self._cc = CgsnClientFactory.create_instance()
        self._cc.set_listener(self._cgsn_state.listener)
        self._cc.start()

    def tearDown(self):
        self._cc.end_reception()

    def test_get_dcl_status(self):

        dcl_id = DclIds.DCL11
        cmd = MessageIds.DCL_STATUS
        self._cc.send_command(dcl_id, cmd)

        # TODO instead of sleep, use AsyncResult or similar mechanism
        sleep(2)

        ack_nack = self._cgsn_state.get_ack_nack(dcl_id, cmd)
        self.assertTrue(MessageIds.ACK, ack_nack)<commit_msg>skip CGSN tests if env var not defined<commit_after>#!/usr/bin/env python

"""
@package ion.agents.platform.cgsn.test.test_cgsn_client
@file    ion/agents/platform/cgsn/test/test_cgsn_client.py
@author  <NAME>
@brief   preliminary tests
"""

__author__ = '<NAME>'
__license__ = 'Apache 2.0'


from pyon.public import log
from pyon.util.unit_test import IonUnitTestCase
from unittest import skipIf
import os

from gevent import sleep

from ion.agents.platform.cgsn.cgsn_client_factory import CgsnClientFactory
from ion.agents.platform.cgsn.cgsn_state import CgsnState
from ion.agents.platform.cgsn.defs import DclIds, MessageIds


@skipIf(os.getenv('CGSN', None) is None, "CGSN env var not defined")
class Test(IonUnitTestCase):

    def setUp(self):
        self._cgsn_state = CgsnState()
        self._cc = CgsnClientFactory.create_instance()
        self._cc.set_listener(self._cgsn_state.listener)
        self._cc.start()

    def tearDown(self):
        self._cc.end_reception()

    def test_get_dcl_status(self):

        dcl_id = DclIds.DCL11
        cmd = MessageIds.DCL_STATUS
        self._cc.send_command(dcl_id, cmd)

        # TODO instead of sleep, use AsyncResult or similar mechanism
        sleep(2)

        ack_nack = self._cgsn_state.get_ack_nack(dcl_id, cmd)
        self.assertTrue(MessageIds.ACK, ack_nack)
{'fraction_non_alphanumeric': 0.09572784810126582, 'fraction_numerical': 0.003955696202531646, 'mean_word_length': 3.598181818181818, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2760837', 'n_tokens_mistral': 922, 'n_tokens_neox': 886, 'n_words': 175}