Esempio n. 1
0
def test_wave_load_table_expand(wave):
    table1 = json.dumps([0, 1])
    cli.cmdline(["wave", "load", "SI1", "--table", table1])
    table2 = json.dumps(([0] * (512 // 2)) + ([1] * (512 // 2)))
    cli.cmdline(["wave", "load", "SI2", "--table", table2])
    assert AnalogOutput("SI1").waveform_table == AnalogOutput(
        "SI2").waveform_table
Esempio n. 2
0
def test_collect_json_file(collect, tmp_path):
    la_tmp_json = str(tmp_path / "logic_analyzer.json")
    cli.cmdline([
        "collect",
        "logic_analyzer",
        "--channels",
        str(LA_CHANNELS),
        "--output",
        la_tmp_json,
        "--json",
    ])
    with open(la_tmp_json) as json_file:
        output = json.load(json_file)
        assert len(output) == LA_CHANNELS
        assert len(list(output.values())[0]) == EVENTS

    scope_tmp_json = str(tmp_path / "oscilloscope.json")
    cli.cmdline([
        "collect",
        "oscilloscope",
        "--channels",
        str(SCOPE_CHANNELS),
        "--output",
        scope_tmp_json,
        "--json",
    ])
    with open(scope_tmp_json) as json_file:
        output = json.load(json_file)
        assert len(output) == 1 + SCOPE_CHANNELS
        assert len(list(output.values())[0]) == SAMPLES
Esempio n. 3
0
def test_collect_csv_file(collect, tmp_path):
    la_temp_csv = str(tmp_path / "logic_analyzer.csv")
    cli.cmdline([
        "collect",
        "logic_analyzer",
        "--channels",
        str(LA_CHANNELS),
        "--output",
        la_temp_csv,
    ])
    with open(la_temp_csv) as csv_file:
        output = list(csv.reader(csv_file.read().splitlines()))
        assert len(output[0]) == LA_CHANNELS
        assert len(output) == 1 + EVENTS

    scope_temp_csv = str(tmp_path / "oscilloscope.csv")
    cli.cmdline([
        "collect",
        "oscilloscope",
        "--channels",
        str(SCOPE_CHANNELS),
        "--output",
        scope_temp_csv,
    ])
    with open(scope_temp_csv) as csv_file:
        output = list(csv.reader(csv_file.read().splitlines()))
        assert len(output[0]) == 1 + SCOPE_CHANNELS
        assert len(output) == 1 + SAMPLES
Esempio n. 4
0
def test_collect_csv_stdout(collect, capsys):
    cli.cmdline(["collect", "logic_analyzer", "--channels", str(LA_CHANNELS)])
    output = list(csv.reader(capsys.readouterr().out.splitlines()))
    assert len(output[0]) == LA_CHANNELS
    assert len(output) == 1 + EVENTS

    cli.cmdline(["collect", "oscilloscope", "--channels", str(SCOPE_CHANNELS)])
    output = list(csv.reader(capsys.readouterr().out.splitlines()))
    assert len(output[0]) == 1 + SCOPE_CHANNELS
    assert len(output) == 1 + SAMPLES
Esempio n. 5
0
def test_wave_load_tablefile_expand(wave, tmp_path):
    table1_tmp_json = str(tmp_path / "table1.json")
    with open(table1_tmp_json, "w") as json_file:
        json.dump([0, 1], json_file)
    cli.cmdline(["wave", "load", "SI1", "--table-file", table1_tmp_json])
    table2_tmp_json = str(tmp_path / "table2.json")
    with open(table2_tmp_json, "w") as json_file:
        json.dump(([0] * (512 // 2)) + ([1] * (512 // 2)), json_file)
    cli.cmdline(["wave", "load", "SI2", "--table-file", table2_tmp_json])
    assert AnalogOutput("SI1").waveform_table == AnalogOutput(
        "SI2").waveform_table
Esempio n. 6
0
def test_wave_load_table(wave, mocker):
    wavegen = WaveformGenerator(mocker.Mock())
    wavegen.load_function("SI1", "tria")

    def tria(x):
        return AnalogOutput.RANGE[1] * (abs(x % 4 - 2) - 1)

    span = [-1, 3]
    x = np.arange(span[0], span[1], (span[1] - span[0]) / 512)
    table = json.dumps(tria(x).tolist())
    cli.cmdline(["wave", "load", "SI2", "--table", table])
    assert AnalogOutput("SI1").waveform_table == AnalogOutput(
        "SI2").waveform_table
Esempio n. 7
0
def test_wave_load_tablefile(wave, mocker, tmp_path):
    wavegen = WaveformGenerator(mocker.Mock())
    wavegen.load_function("SI1", "tria")

    def tria(x):
        return AnalogOutput.RANGE[1] * (abs(x % 4 - 2) - 1)

    span = [-1, 3]
    x = np.arange(span[0], span[1], (span[1] - span[0]) / 512)
    table_tmp_json = str(tmp_path / "table.json")
    with open(table_tmp_json, "w") as json_file:
        json.dump(tria(x).tolist(), json_file)
    cli.cmdline(["wave", "load", "SI2", "--table-file", table_tmp_json])
    assert AnalogOutput("SI1").waveform_table == AnalogOutput(
        "SI2").waveform_table
Esempio n. 8
0
def test_collect_json_stdout(collect, capsys):
    cli.cmdline([
        "collect", "logic_analyzer", "--channels",
        str(LA_CHANNELS), "--json"
    ])
    output = json.loads(capsys.readouterr().out)
    assert len(output) == LA_CHANNELS
    assert len(list(output.values())[0]) == EVENTS

    cli.cmdline([
        "collect", "oscilloscope", "--channels",
        str(SCOPE_CHANNELS), "--json"
    ])
    output = json.loads(capsys.readouterr().out)
    assert len(output) == 1 + SCOPE_CHANNELS
    assert len(list(output.values())[0]) == SAMPLES