Exemplo n.º 1
0
def test_file_option():
    file_option = FileOption("File")
    assert file_option.file_mode == FileOption.ANYFILE
    assert file_option.file_type == ''
    assert file_option.file_endings is None
    assert file_option.path is None
    assert file_option.start_path == Path()
Exemplo n.º 2
0
def test_file_options(config):
    file_option = FileOption("File", Path("phypigui/test/resources/test_data/test_force.ppg"))

    assert config.add_file_option(file_option) == 0
    assert len(config.file_options) == 1
    assert config.file_options is not config._ConfigModel__file_options

    path = Path("phypigui/test/resources/test_data/test_temp_celsius.ppg")
    config.set_file_option(0, path)
    assert config.file_options[0].path == path

    with pytest.raises(IndexError):
        config.set_file_option(999999999999, Path())
Exemplo n.º 3
0
def test_set_file_option():
    config = ConfigModel()
    for i in range(10):
        config.add_file_option(FileOption(""))
    item = create_item(config, 1)

    with pytest.raises(IndexError):
        item.set_file_option(-1, Path(""))

    with pytest.raises(IndexError):
        item.set_file_option(10, Path(""))

    item.set_file_option(4, Path("/PhyPiDAQ/phypigui/test/resources/test_data/test_force.ppg"))
    assert item.config.file_options[4].path == Path("/PhyPiDAQ/phypigui/test/resources/test_data/test_force.ppg")
Exemplo n.º 4
0
def test_set_config():
    config = ConfigModel()
    config.add_bool_option(BoolOption("", "", False))
    config.add_enum_option(EnumOption("", TestEnum, "", 0))
    config.add_file_option(FileOption(""))
    config.add_num_option(NumOption("", "", 0))
    item = create_item(config, 1)

    config.set_bool_option(0, True)
    config.set_enum_option(0, 1)
    config.set_num_option(0, 5.5)
    config.set_file_option(0, Path("/PhyPiDAQ/phypigui/test/resources/test_data/test_force.ppg"))
    item.set_config(config)

    assert item.config.bool_options[0].enabled is True
    assert item.config.enum_options[0].selection == 1
    assert item.config.num_options[0].number == 5.5
    assert item.config.file_options[0].path == Path("/PhyPiDAQ/phypigui/test/resources/test_data/test_force.ppg")
Exemplo n.º 5
0
def test_any_file():
    file_option = FileOption("File", file_opening_mode=FileOption.ANYFILE)

    file_option.path = file
    assert file_option.path == file
    assert file_option.start_path == Path()

    file_option.path = dir
    assert file_option.path == dir
    assert file_option.start_path == dir

    file_option.path = Path("doest_exist.no")

    file_option.path = None
    assert file_option.path is None
Exemplo n.º 6
0
def test_dir():
    file_option = FileOption("File", file_opening_mode=FileOption.DIR)

    file_option.path = dir
    assert file_option.path == dir
    assert file_option.start_path == dir

    with pytest.raises(IllegalFileType):
        file_option.path = file
    assert file_option.path == dir
    assert file_option.start_path == dir

    with pytest.raises(PathDoesntExist):
        file_option.path = Path("doesnt_exist.no")
    with pytest.raises(PathDoesntExist):
        file_option.path = Path("phypigui/doesnt_exist/")

    file_option.path = None
    assert file_option.path is None
Exemplo n.º 7
0
def test_existing_file():
    file_option = FileOption("File", file_opening_mode=FileOption.EXISTINGFILE)

    file_option.path = file
    assert file_option.path == file
    assert file_option.start_path == Path()

    with pytest.raises(IllegalFileType):
        file_option.path = dir
    assert file_option.path == file
    assert file_option.start_path == Path()

    with pytest.raises(PathDoesntExist):
        file_option.path = Path("doest_exist.no")

    file_option.path = None
    assert file_option.path is None
Exemplo n.º 8
0
def test_file_endings():
    file_option = FileOption("File", file_opening_mode=FileOption.EXISTINGFILE)

    file_option.path = file
    assert file_option.path == file
    file_option.path = image
    assert file_option.path == image

    file_option = FileOption("File", file_opening_mode=FileOption.EXISTINGFILE, file_endings=['ppg'])
    file_option.path = file
    assert file_option.path == file
    with pytest.raises(IllegalFileType):
        file_option.path = image

    file_option = FileOption("File", file_opening_mode=FileOption.EXISTINGFILE, file_endings=['py'])
    with pytest.raises(IllegalFileType):
        file_option.path = file
    with pytest.raises(IllegalFileType):
        file_option.path = image

    file_option = FileOption("File", file_opening_mode=FileOption.EXISTINGFILE, file_endings=[])
    file_option.path = file
    assert file_option.path == file
    file_option.path = image
    assert file_option.path == image

    file_option = FileOption("File", file_opening_mode=FileOption.EXISTINGFILE, file_endings=['ppg', 'png'])
    file_option.path = file
    assert file_option.path == file
    file_option.path = image
    assert file_option.path == image

    file_option = FileOption("File", file_opening_mode=FileOption.DIR, file_endings=['ppg', 'png'])
    file_option.path = dir
    assert file_option.path == dir
    with pytest.raises(IllegalFileType):
        file_option.path = file