コード例 #1
0
def test_constructor_notdefault_single_base_cls_0_params_success():
    operator = pca.PCA(base_cls=pca.sklearn_pca[-1], verbose=False)
    assert isinstance(operator, pca.sklearn_pca[-1])
    assert isinstance(operator, pca.sklearn_pca[-2])

    #minibatch sparsePCA inherits from sparsepca so we need to ignore sparse pca
    assert not (isinstance(operator, tuple(pca.sklearn_pca[:-2])))
コード例 #2
0
def test_constructor_auto_multi_param_single_clash_force_fail_argratio():
    test_bases = [skld.SparsePCA]
    operator = pca.PCA(base_cls=test_bases,
                       alpha=1,
                       whiten=2,
                       n_iter=1,
                       force=True)
コード例 #3
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the PCA switch platform."""

    if discovery_info is None:
        return

    serial_device = discovery_info["device"]

    try:
        pca = pypca.PCA(serial_device)
        pca.open()

        entities = [SmartPlugSwitch(pca, device) for device in pca.get_devices()]
        add_entities(entities, True)

    except SerialException as exc:
        _LOGGER.warning("Unable to open serial port: %s", exc)
        return

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, pca.close)

    pca.start_scan()
コード例 #4
0
def test_constructor_auto_1_param_no_default_success():
    operator = pca.PCA(n_components=1, verbose=False, default=False)
    tf = False
    for klass in pca.sklearn_pca:
        if (isinstance(operator, klass)
                and klass not in pca.default_sklearn_pca):
            tf = True
    assert tf
コード例 #5
0
ファイル: switch.py プロジェクト: pedrolamas/home-assistant
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the PCA switch platform."""
    import pypca
    from serial import SerialException

    name = config[CONF_NAME]
    usb_device = config[CONF_DEVICE]

    try:
        pca = pypca.PCA(usb_device)
        pca.open()
        entities = [
            SmartPlugSwitch(pca, device, name) for device in pca.get_devices()
        ]
        add_entities(entities, True)

    except SerialException as exc:
        _LOGGER.warning("Unable to open serial port: %s", exc)
        return

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, pca.close)

    pca.start_scan()
コード例 #6
0
ファイル: switch.py プロジェクト: OpenPeerPower/core
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the PCA switch platform."""

    if discovery_info is None:
        return

    serial_device = discovery_info["device"]

    try:
        pca = pypca.PCA(serial_device)
        pca.open()

        entities = [
            SmartPlugSwitch(pca, device) for device in pca.get_devices()
        ]
        add_entities(entities, True)

    except SerialException as exc:
        _LOGGER.warning("Unable to open serial port: %s", exc)
        return

    opp.bus.listen_once(EVENT_OPENPEERPOWER_STOP, pca.close)

    pca.start_scan()
コード例 #7
0
def test_constructor_single_base_fail_string():
    operator = pca.PCA(base_cls='foobar')
コード例 #8
0
def test_constructor_auto_1_param_default_fail():
    operator = pca.PCA(alpha=1)
コード例 #9
0
def test_constructor_single_base_fail_bad_type():
    operator = pca.PCA(base_cls=list)
コード例 #10
0
def test_constructor_auto_multi_param_single_clash_fail():
    try:
        operator = pca.PCA(alpha=1, whiten=2, n_iter=1)
    except ValueError as e:
        e = str(e)
        assert ("matches ['alpha" in e and "mismatches ['whiten" in e)
コード例 #11
0
def test_constructor_auto_multi_param_single_clash_force():
    test_bases = [
        skld.PCA, skld.TruncatedSVD, skld.KernelPCA, skld.IncrementalPCA
    ]
    operator = pca.PCA(base_cls=test_bases, whiten=2, n_iter=1, force=True)
コード例 #12
0
def test_constructor_multi_base_cls_0params_success():
    operator = pca.PCA(base_cls=pca.sklearn_pca[:2], verbose=False)
    for klass in pca.sklearn_pca[:2]:
        assert isinstance(operator, klass)
    assert not isinstance(operator, tuple(pca.sklearn_pca[2:]))
コード例 #13
0
def test_constructor_auto_2_param_multi_clash_fail():
    try:
        operator = pca.PCA(alpha=1, whiten=2, verbose=True)
    except ValueError as e:
        e = str(e)
        assert ('alpha' in e and 'whiten' in e)
コード例 #14
0
def test_constructor_single_base_cls_0params_success():
    operator = pca.PCA(base_cls=skld.PCA, verbose=False)
    assert isinstance(operator, skld.PCA)
    assert not isinstance(operator, tuple(pca.sklearn_pca[1:]))
コード例 #15
0
def test_constructor_auto_1_param_default_success():
    operator = pca.PCA(n_components=1, verbose=False)
    for klass in pca.sklearn_pca[:2]:
        assert isinstance(operator, klass)
    assert not isinstance(operator, tuple(pca.sklearn_pca[2:]))
コード例 #16
0
def test_constructor_list_base_fail_bad_type():
    operator = pca.PCA(base_cls=[skld.PCA, list])
コード例 #17
0
def test_constructor_auto_default_0_params_success():
    operator = pca.PCA(verbose=False)
    for klass in pca.sklearn_pca[:2]:
        assert isinstance(operator, klass)
    assert not (isinstance(operator, tuple(pca.sklearn_pca[2:])))
コード例 #18
0
def test_constructor_list_base_fail_bad_string():
    operator = pca.PCA(base_cls=[skld.PCA, 'foo'])