示例#1
0
def test_source_file(mocker):
    input_data = 'input1\ninput2\n'
    mock_open = mocker.mock_open(read_data=input_data)
    mocker.patch("builtins.open", mock_open)
    src = Source.from_file("test.txt")
    rows: List[Row] = [x for x in src]
    assert rows == [Row('test.txt', 'input1'), Row('test.txt', 'input2')]
示例#2
0
def test_source_file_gz(mocker):
    input_data = 'input3\ninput4\n'
    mock_open = mocker.mock_open(read_data=input_data)
    mocker.patch("gzip.open", mock_open)
    src = Source.from_file("test.txt.gz")
    rows: List[Row] = [x for x in src]
    assert rows == [Row('test.txt.gz', 'input3'), Row('test.txt.gz', 'input4')]
示例#3
0
def test_source_sample_orion():
    src = SourceSampleOrion(count=5, delay=0)
    rows: List[Row] = [x for x in src]
    assert len(rows) == 5
    assert rows[0] == Row('orionSample', 'Room1;23;720')
    assert rows[1] == Row('orionSample', 'Room2;21;711')
    assert "Room5;" in rows[4].record
示例#4
0
def test_source_file_zip():
    zipname = pkg_resources.resource_filename(__name__, "data/test.txt.zip")
    src = Source.from_file(zipname)
    rows: List[Row] = [x for x in src]
    assert rows == [
        Row('test.txt.zip', 'input5'),
        Row('test.txt.zip', 'input6')
    ]
示例#5
0
def test_source_stdin(mocker):
    mocker.patch('sys.stdin', {"input1", "input2"})
    src = SourceStdin()
    rows: List[Row] = [x for x in src]
    assert len(rows) == 2
    # pytest capture input/output could mess the order
    assert Row('user', 'input1') in rows
    assert Row('user', 'input2') in rows
示例#6
0
    def __iter__(self):
        obj = self.json_obj
        if self.path:
            obj = self.jsonpath(self.path)

        if isinstance(obj, list):
            for j in obj:
                yield Row(self.provider, j)
        else:
            yield Row(self.provider, obj)
示例#7
0
    def __iter__(self):
        obj = self.json_obj
        path=self.path.split('.') if self.path else None
        if path:
            obj = self._jsonpath(path)

        if isinstance(obj, list):
            for j in obj:
                yield Row(self.provider, j)
        else:
            yield Row(self.provider, obj)
 def __iter__(self):
     response = requests.get(self.url,
                             headers=self.headers,
                             params=self.params)
     response.raise_for_status()
     for commit in response.json():
         yield Row(self.provider, commit)
示例#9
0
def test_build_entity_sample_orion():
    m = build_entity_sample_orion(Row(record="Room1;21.7;720"))
    assert m['id'] == "Room1"
    assert m['type'] == "Room"
    assert m['temperature']['value'] == 21.7
    assert m['temperature']['type'] == "Float"
    assert m['pressure']['value'] == 720
    assert m['pressure']['type'] == "Integer"
示例#10
0
 def __iter__(self):
     i: int = 0
     if self.count >= 1:  # 1st element is fixed
         yield Row("orionSample", "Room1;23;720")
         i += 1
         time.sleep(self.delay)
     if self.count >= 2:  # 2nd element is fixed
         yield Row("orionSample", "Room2;21;711")
         i += 1
         time.sleep(self.delay)
     # next elements are randomized
     while i < self.count:
         yield Row(
             "orionSample",
             f"Room{i%9+1};{round(random.uniform(-10,50), 1)};{random.randint(700,1000)}"
         )
         i += 1
         time.sleep(self.delay)
示例#11
0
 def _callback(self, msg: MQTTMessage):
     payload = str(msg.payload.decode("utf-8"))
     self._queue.put(Row(msg.topic, payload))
示例#12
0
 def __iter__(self):
     for row in self.rows:
         record = ";".join(
             [str(cell.value) if cell.value else "" for cell in row])
         logger.debug(f"{self.provider=}{record=}")
         yield Row(self.provider, record)
示例#13
0
def test_build_entity_unknown():
    m = build_entity_unknown(Row(record="dummy"))
    assert "Unknown:" in m['id']
    assert m['type'] == "Unknown"
    assert m['rawData']['type'] == "Text"
    assert m['rawData']['value'] == "dummy"
def publisher(src: SourceMqtt):
    for temp in range(5):
        src._queue.put(Row("sensor/temperature", temp))
示例#15
0
def test_source_single():
    src = SourceSingle("test1")
    rows: List[Row] = [x for x in src]
    assert len(rows) == 1
    assert rows[0] == Row('user', 'test1')
示例#16
0
def test_source_list():
    src = SourceStream(["test1", "test2"])
    rows: List[Row] = [x for x in src]
    assert len(rows) == 2
    assert rows[0] == Row('user', 'test1')
    assert rows[1] == Row('user', 'test2')