Exemplo n.º 1
0
    async def test_stream_move(self):
        # can move by ID
        await self.node.data_stream_move(1, 2)
        self.assertEqual(self.session.method, 'PUT')
        self.assertEqual(self.session.path, "/stream/move.json")
        self.assertEqual(self.session.request_data, {
            'src_id': 1,
            'dest_id': 2
        })
        # can move by path
        await self.node.data_stream_move('/a/path', '/b/path')
        self.assertEqual(self.session.method, 'PUT')
        self.assertEqual(self.session.path, "/stream/move.json")
        self.assertEqual(self.session.request_data, {
            'src_path': '/a/path',
            'dest_path': '/b/path'
        })

        # can move by Folder and DataStream
        src = DataStream()
        src.id = 1
        dest = Folder()
        dest.id = 2
        await self.node.data_stream_move(src, dest)
        self.assertEqual(self.session.path, "/stream/move.json")
        self.assertEqual(self.session.request_data, {
            'src_id': 1,
            'dest_id': 2
        })
Exemplo n.º 2
0
    async def test_annotation_get(self):
        json = [{
            "id": 1,
            "stream_id": 1,
            "title": "note",
            "start": 100,
            "end": None,
            "content": "nothing special"}]

        # get by stream id
        self.session.response_data = json
        await self.node.annotation_get(1)
        req_data = self.session.request_data
        self.assertEqual(req_data["stream_id"], 1)

        # get by stream object
        stream = DataStream(name="test")
        stream.id = 100
        await self.node.annotation_get(stream)
        req_data = self.session.request_data
        self.assertEqual(req_data["stream_id"], 100)

        # get by stream path
        await self.node.annotation_get("/stream/path")
        req_data = self.session.request_data
        self.assertEqual(req_data["stream_path"], "/stream/path")

        # error otherwise
        with self.assertRaises(errors.ApiError):
            await self.node.annotation_get({})
Exemplo n.º 3
0
async def start_standalone_procs2(node: api.BaseNode):
    # proc3 tries to write to /counting/plus3 with wrong dtype
    p3 = subprocess.run(build_standalone_args("proc3"),
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE,
                        universal_newlines=True,
                        timeout=3)
    assert p3.stderr.find("layout") != -1

    #  proc4 reads /counting/base and writes to /counting/plus3
    p1 = subprocess.Popen(build_standalone_args("proc1"))

    stream = DataStream()
    stream.name = "int8"
    stream.datatype = "int8"
    for x in range(3):
        e = Element()
        e.name = 'item%d' % x
        e.index = x
        stream.elements.append(e)
    await node.data_stream_create(stream, "/exists")

    # proc5 tries to write to /exists/int8 with wrong element count
    p4 = subprocess.run(build_standalone_args("proc4"),
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE,
                        universal_newlines=True)
    assert p4.stderr.find("layout") != -1

    return [p1]
Exemplo n.º 4
0
 async def test_annotation_create(self):
     annotation = Annotation(title="note",
                             start=100,
                             content="nothing special")
     json = {
         "id": 1,
         "stream_id": 1,
         "title": "nozte",
         "start": 100,
         "end": None,
         "content": "nothing special"}
     self.session.response_data = json
     # create by stream path
     await self.node.annotation_create(annotation, '/a/path')
     self.assertEqual(self.session.request_data["stream_path"], "/a/path")
     stream = DataStream(name="test")
     stream.id = 100
     # create by DataStream object
     await self.node.annotation_create(annotation, stream)
     self.assertEqual(self.session.request_data["stream_id"], 100)
     # create by DataStream id
     await self.node.annotation_create(annotation, 100)
     self.assertEqual(self.session.request_data["stream_id"], 100)
     # errors with invalid stream type
     with self.assertRaises(errors.ApiError):
         await self.node.annotation_create(annotation, [1, 2])
Exemplo n.º 5
0
 async def _process_inline_configuration(self, pipe_config,
                                         configured_streams):
     # if there is an inline configuration add it to the configured streams dict
     # returns the full path to the stream
     (path, name, inline_config) = parse_pipe_config(pipe_config)
     if inline_config == '':
         return pipe_config  # the pipe config is just the full path
     full_path = "/".join([path, name])
     # inline config exists
     (datatype, element_names) = parse_inline_config(inline_config)
     datatype = datatype.name.lower(
     )  # API models are plain text attributes
     # make sure inline config agrees with stream config if present
     if full_path in configured_streams:
         stream = configured_streams[full_path]
         if datatype != stream.datatype.lower() or \
                 len(stream.elements) != len(element_names):
             raise ConfigurationError(
                 f"Invalid configuration: [{name}] inline format does not match config file"
             )
     # otherwise create a stream object from the inline config
     stream = DataStream()
     stream.name = name
     stream.decimate = True
     stream.datatype = datatype
     for i in range(len(element_names)):
         e = Element()
         e.name = element_names[i]
         e.index = i
         stream.elements.append(e)
     configured_streams[full_path] = stream
     return full_path
Exemplo n.º 6
0
    async def test_folder_move_errors(self):
        self.session.method = None
        with self.assertRaises(errors.ApiError):
            await self.node.folder_move(DataStream(), '/b/path')
        self.assertIsNone(self.session.method)

        with self.assertRaises(errors.ApiError):
            await self.node.folder_move('/a/path', DataStream())
        self.assertIsNone(self.session.method)
Exemplo n.º 7
0
def build_stream(name, inline_config: str) -> DataStream:
    s = DataStream()
    s.name = name
    (datatype, names) = parse_inline_config(inline_config)
    s.datatype = datatype.name.lower(),
    i = 0
    for name in names:
        e = Element()
        e.name = name
        e.index = i
        s.elements.append(e)
    return s
Exemplo n.º 8
0
    async def test_stream_move_errors(self):
        self.session.method = None
        with self.assertRaises(errors.ApiError):
            await self.node.data_stream_move(DataStream(), [])
        self.assertIsNone(self.session.method)

        with self.assertRaises(errors.ApiError):
            await self.node.data_stream_move([], Folder())
        self.assertIsNone(self.session.method)
Exemplo n.º 9
0
    async def test_stream_delete(self):
        # can delete by ID
        await self.node.data_stream_delete(1)
        self.assertEqual(self.session.method, 'DELETE')
        self.assertEqual(self.session.path, "/stream.json")
        self.assertEqual(self.session.request_data, {'id': 1})
        # can delete by path
        await self.node.data_stream_delete('/a/path')
        self.assertEqual(self.session.method, 'DELETE')
        self.assertEqual(self.session.path, "/stream.json")
        self.assertEqual(self.session.request_data, {'path': '/a/path'})

        # can delete by DataStream
        src = DataStream()
        src.id = 1
        await self.node.data_stream_delete(src)
        self.assertEqual(self.session.method, 'DELETE')
        self.assertEqual(self.session.path, "/stream.json")
        self.assertEqual(self.session.request_data, {'id': 1})
Exemplo n.º 10
0
 def _create_stub_stream(self, name, layout):
     # if API information is not available (coming from a remote node) then
     # create a stream with the right layout to use as a substitute
     # NOTE: this could be improved but since the remote capability isn't
     # really used this should be fine for now
     (dtype, num_elements) = layout.split('_')
     return DataStream(
         name=f"STUB:{name}",
         description="automatically generated stub",
         datatype=dtype,
         elements=[Element(name=f"E{i}") for i in range(int(num_elements))])
Exemplo n.º 11
0
    async def test_stream_get(self):
        target = build_stream('test', 'int8[a,b]')
        target.id = 1
        self.session.response_data = target.to_json()
        stream = await self.node.data_stream_get(1)
        self.assertEqual(stream.to_json(), target.to_json())
        self.assertEqual(self.session.method, 'GET')
        self.assertEqual(self.session.path, "/stream.json")
        self.assertEqual(self.session.request_data, {'id': 1})
        # can get by path
        await self.node.data_stream_get('/a/path')
        self.assertEqual(self.session.method, 'GET')
        self.assertEqual(self.session.path, "/stream.json")
        self.assertEqual(self.session.request_data, {'path': '/a/path'})

        # can get by DataStream
        src = DataStream()
        src.id = 1
        await self.node.data_stream_get(src)
        self.assertEqual(self.session.path, "/stream.json")
        self.assertEqual(self.session.request_data, {'id': 1})
Exemplo n.º 12
0
async def _create_stream(stream_path, hdf_root, node):
    # try to get the elements from the hdf attrs
    try:
        element_json = json.loads(hdf_root.attrs['element_json'])
        elements = [elem_from_json(e) for e in element_json]
    except KeyError:
        # just make default elements
        num_elements = hdf_root['data'].shape[1]
        elements = [Element("Element %d" % i) for i in range(num_elements)]

    stream_name = stream_path.split('/')[-1]
    folder = '/'.join(stream_path.split('/')[:-1])
    if folder == '':
        raise click.ClickException(
            "Invalid stream path, must include a folder")
    new_stream = DataStream(stream_name)
    new_stream.datatype = hdf_root['data'].dtype.name
    new_stream.elements = elements
    stream_obj = await node.data_stream_create(new_stream, folder)
    print("creating [%s]" % stream_path)
    return stream_obj
Exemplo n.º 13
0
 async def test_folder_delete_errors(self):
     self.session.method = None
     with self.assertRaises(errors.ApiError):
         await self.node.folder_delete(DataStream(), recursive=False)
     self.assertIsNone(self.session.method)
Exemplo n.º 14
0
 async def test_folder_get_errors(self):
     self.session.method = None
     with self.assertRaises(errors.ApiError):
         await self.node.folder_get(DataStream())
     self.assertIsNone(self.session.method)