Пример #1
0
    def test_map_attr_opt(self):
        """Test a Source and a Map operator with optional types.
           Including with operator parameters and output clauses.
        """
        if ("TestSas" in str(self)) or 'CP4D_URL' in os.environ:
            print('Testing with Streams supporting optional types')
        else:
            if 'STREAMS_INSTALL' in os.environ:
                Tester.require_streams_version(self, '4.3')
            else:
                self.skipTest("STREAMS_INSTALL not set")

        topo = Topology('test_map_attr_opt')
        this_dir = os.path.dirname(os.path.realpath(__file__))
        spl_dir = os.path.join(os.path.dirname(os.path.dirname(this_dir)),
                               'spl')
        tk_dir = os.path.join(spl_dir, 'testtkopt')
        streamsx.spl.toolkit.add_toolkit(topo, tk_dir)
        schema = 'tuple<' \
            'rstring r, ' \
            'optional<rstring> orv, ' \
            'optional<rstring> ornv, ' \
            'int32 i32, ' \
            'optional<int32> oi32v, ' \
            'optional<int32> oi32nv>'
        s = op.Source(topo,
                      "testgen::TypeLiteralTester",
                      schema,
                      params={
                          'r': 'a string',
                          'orv': 'optional string',
                          'ornv': None,
                          'i32': 123,
                          'oi32v': 456,
                          'oi32nv': streamsx.spl.types.null()
                      })
        f = op.Map('spl.relational::Functor', s.stream, schema=schema)
        f.orv = f.output("null")
        f.ornv = f.output('"string value"')
        f.oi32v = f.output(streamsx.spl.types.null())
        f.oi32nv = f.output('789')
        tester = Tester(topo)
        tester.contents(s.stream, [{
            'r': 'a string',
            'orv': 'optional string',
            'ornv': None,
            'i32': 123,
            'oi32v': 456,
            'oi32nv': None
        }])
        tester.contents(f.stream, [{
            'r': 'a string',
            'orv': None,
            'ornv': 'string value',
            'i32': 123,
            'oi32v': None,
            'oi32nv': 789
        }])
        tester.test(self.test_ctxtype, self.test_config)
 def test_object_to_schema_dict_opt(self):
     Tester.require_streams_version(self, '4.3')
     topo = Topology()
     s = topo.source([1,2,3])
     st = s.map(lambda x :
         {'x':None} if x == 2
         else {'x':None, 'y':33} if x == 3
         else {'x':x},
             schema='tuple<optional<int32> x, optional<int32> y>')
     tester = Tester(topo)
     tester.contents(st, [{'x':1, 'y':None}, {'x':None, 'y':None}, {'x':None, 'y':33}])
     tester.test(self.test_ctxtype, self.test_config)
Пример #3
0
    def test_optional_blob_type(self):
        Tester.require_streams_version(self, '4.3')
        topo = Topology()
        streamsx.spl.toolkit.add_toolkit(topo, stu._tk_dir('testtkpy'))
        data = ['Hello', 'Blob', 'Did', 'you', 'reset']
        s = topo.source(data)
        s = s.as_string()

        toBlob = op.Map("com.ibm.streamsx.topology.pytest.pytypes::ToBlob", s,
                        'tuple<optional<blob> ob>')

        bt = op.Map("com.ibm.streamsx.topology.pytest.pytypes::BlobTest",
                    toBlob.stream, 'tuple<rstring string>', {'keep': True})

        tester = Tester(topo)
        tester.contents(bt.stream, data)
        tester.test(self.test_ctxtype, self.test_config)
Пример #4
0
 def test_map_attr_opt(self):
     """Test a Source and a Map operator with optional types.
        Including with operator parameters and output clauses.
     """
     Tester.require_streams_version(self, '4.3')
     topo = Topology('test_map_attr_opt')
     this_dir = os.path.dirname(os.path.realpath(__file__))
     spl_dir = os.path.join(os.path.dirname(os.path.dirname(this_dir)), 'spl')
     tk_dir = os.path.join(spl_dir, 'testtkopt')
     streamsx.spl.toolkit.add_toolkit(topo, tk_dir)
     schema = 'tuple<' \
         'rstring r, ' \
         'optional<rstring> orv, ' \
         'optional<rstring> ornv, ' \
         'int32 i32, ' \
         'optional<int32> oi32v, ' \
         'optional<int32> oi32nv>'
     s = op.Source(topo, "testgen::TypeLiteralTester", schema, params = {
         'r': 'a string',
         'orv': 'optional string',
         'ornv': None,
         'i32': 123,
         'oi32v': 456,
         'oi32nv': streamsx.spl.types.null()})
     f = op.Map('spl.relational::Functor', s.stream, schema = schema)
     f.orv = f.output("null")
     f.ornv = f.output('"string value"')
     f.oi32v = f.output(streamsx.spl.types.null())
     f.oi32nv = f.output('789')
     tester = Tester(topo)
     tester.contents(s.stream, [{
         'r': 'a string',
         'orv': 'optional string',
         'ornv': None,
         'i32': 123,
         'oi32v': 456,
         'oi32nv': None}])
     tester.contents(f.stream, [{
         'r': 'a string',
         'orv': None,
         'ornv': 'string value',
         'i32': 123,
         'oi32v': None,
         'oi32nv': 789}])
     tester.test(self.test_ctxtype, self.test_config)
 def test_map_opt(self):
     """Test optional type value and no value are passed correctly
     """
     Tester.require_streams_version(self, '4.3')
     topo = Topology('test_map_opt')
     schema='tuple<optional<uint64> i>'
     b = op.Source(topo, "spl.utility::Beacon", schema,
         params = {'iterations':3})
     b.i = b.output('IterationCount() % 2ul == 0ul ?' +
        'IterationCount() : (optional<uint64>) null')
     s = b.stream
     f = s.map(lambda tuple :
         (1,) if tuple['i'] == None
         else (None,) if tuple['i'] == 2
         else (tuple['i'],), schema=schema)
     tester = Tester(topo)
     tester.contents(s, [{'i':0}, {'i':None}, {'i':2}])
     tester.contents(f, [{'i':0}, {'i':1}, {'i':None}])
     tester.test(self.test_ctxtype, self.test_config)
Пример #6
0
 def test_map_opt(self):
     """Test optional type value and no value are passed correctly
     """
     Tester.require_streams_version(self, '4.3')
     topo = Topology('test_map_opt')
     schema = 'tuple<optional<uint64> i>'
     b = op.Source(topo,
                   "spl.utility::Beacon",
                   schema,
                   params={'iterations': 3})
     b.i = b.output('IterationCount() % 2ul == 0ul ?' +
                    'IterationCount() : (optional<uint64>) null')
     s = b.stream
     f = s.map(lambda tuple: (1, ) if tuple['i'] == None else (None, )
               if tuple['i'] == 2 else (tuple['i'], ),
               schema=schema)
     tester = Tester(topo)
     tester.contents(s, [{'i': 0}, {'i': None}, {'i': 2}])
     tester.contents(f, [{'i': 0}, {'i': 1}, {'i': None}])
     tester.test(self.test_ctxtype, self.test_config)
Пример #7
0
 def test_object_to_schema_dict_opt(self):
     Tester.require_streams_version(self, '4.3')
     topo = Topology()
     s = topo.source([1, 2, 3])
     st = s.map(lambda x: {'x': None} if x == 2 else {
         'x': None,
         'y': 33
     } if x == 3 else {'x': x},
                schema='tuple<optional<int32> x, optional<int32> y>')
     tester = Tester(topo)
     tester.contents(st, [{
         'x': 1,
         'y': None
     }, {
         'x': None,
         'y': None
     }, {
         'x': None,
         'y': 33
     }])
     tester.test(self.test_ctxtype, self.test_config)
    def test_optional_blob_type(self):
        Tester.require_streams_version(self, '4.3')
        topo = Topology()
        streamsx.spl.toolkit.add_toolkit(topo, stu._tk_dir('testtkpy'))
        data = ['Hello', 'Blob', 'Did', 'you', 'reset' ]
        s = topo.source(data)
        s = s.as_string()

        toBlob = op.Map(
            "com.ibm.streamsx.topology.pytest.pytypes::ToBlob",
            s,
            'tuple<optional<blob> ob>')

        bt = op.Map(
            "com.ibm.streamsx.topology.pytest.pytypes::BlobTest",
            toBlob.stream,
            'tuple<rstring string>',
            {'keep': True})
         
        tester = Tester(topo)
        tester.contents(bt.stream, data)
        tester.test(self.test_ctxtype, self.test_config)