<commit_before># Licensed Materials - Property of IBM
# Copyright IBM Corp. 2016
import unittest
import sys
import statistics
from streamsx.topology.tester import Tester

import test_functions
from test_utilities import standalone

try:
    import numpy as np
    skip_numpy = False
except ImportError:
    skip_numpy = True

from streamsx.topology.topology import *
from streamsx.topology import schema
import streamsx.topology.context


class Gen(object):
    def __init__(self, n):
        self.n = n

    def __iter__(self):
        self.c = 0
        self.start = time.time()
        return self

    def __next__(self):
        self.c += 1
        if self.c <= self.n:
            return {'id': random.randint(0, 1000), 'ts':time.time(), 'value': random.random() }
        end = time.time()
        dur = end - self.start
        raise StopIteration()

class M(object):
    def __call__(self, tuple_):
        return statistics.mean([tuple_['value'], 9.3])

def _rand_msg():
    import streamsx.ec
    for _ in range(2000):
        streamsx.ec.is_active()
        yield random.randint(0,3)
        time.sleep(0.001)

class TestLambdas(unittest.TestCase):
  _multiprocess_can_split_ = True

  def setUp(self):
      Tester.setup_standalone(self)
      #Tester.setup_distributed(self)

  def test_TopologyLambdaFilter(self):<commit_msg>Use a package availble in 2.7<commit_after># Licensed Materials - Property of IBM
# Copyright IBM Corp. 2016
import unittest
import sys
import decimal
from streamsx.topology.tester import Tester

import test_functions
from test_utilities import standalone

try:
    import numpy as np
    skip_numpy = False
except ImportError:
    skip_numpy = True

from streamsx.topology.topology import *
from streamsx.topology import schema
import streamsx.topology.context


class Gen(object):
    def __init__(self, n):
        self.n = n

    def __iter__(self):
        self.c = 0
        self.start = time.time()
        return self

    def __next__(self):
        self.c += 1
        if self.c <= self.n:
            return {'id': random.randint(0, 1000), 'ts':time.time(), 'value': random.random() }
        end = time.time()
        dur = end - self.start
        raise StopIteration()

class M(object):
    def __call__(self, tuple_):
        return decimal.Decimal(tuple_['value'])

def _rand_msg():
    import streamsx.ec
    for _ in range(2000):
        streamsx.ec.is_active()
        yield random.randint(0,3)
        time.sleep(0.001)

class TestLambdas(unittest.TestCase):
  _multiprocess_can_split_ = True

  def setUp(self):
      Tester.setup_standalone(self)
      #Tester.setup_distributed(self)

  def test_TopologyLambdaFilter(self):
{'fraction_non_alphanumeric': 0.10014892032762472, 'fraction_numerical': 0.01712583767684289, 'mean_word_length': 2.911208151382824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4424975', 'n_tokens_mistral': 886, 'n_tokens_neox': 838, 'n_words': 225}