Exemple #1
0
def command(args):
    # Create our own tracking instance here because this command might write
    # the configuration file.
    is_write_action = args.setting in [Mode.TRACK, Mode.IGNORE, Mode.RESET]
    if args.shell.is_envprobe_capable:
        local_config_file = ConfigurationFile(
            os.path.join(args.shell.configuration_directory,
                         get_tracking_file_name()),
            VariableTracking.config_schema_local,
            read_only=args.scope != Scope.LOCAL or
            (args.scope == Scope.LOCAL and not is_write_action)
        )
    else:
        local_config_file = None
    global_config_file = ConfigurationFile(
        os.path.join(get_configuration_directory(), get_tracking_file_name()),
        VariableTracking.config_schema_global,
        read_only=args.scope != Scope.GLOBAL or (args.scope == Scope.GLOBAL and
                                                 not is_write_action)
    )
    tracker = VariableTracking(global_config_file, local_config_file)

    if args.default:
        return _handle_default(tracker, args)

    if args.setting == Mode.QUERY:
        return _handle_querying_variable(tracker, args)

    return _handle_setting_variable(tracker, args)
def test_unset_not_set():
    t = VariableTracking()
    t.unset_local("FOO")
    t.unset_global("BAR")

    assert (t.is_tracked("FOO"))
    assert (t.is_tracked("BAR"))
def test_defaults():
    t = VariableTracking()
    t.local_tracking = False
    t.global_tracking = False

    assert (not t.is_tracked("FOO"))

    t.local_tracking = True

    assert (t.is_tracked("FOO"))
def test_empty_config():
    L = nullcontext(dict())
    G = nullcontext(dict())

    t = VariableTracking(L, G)

    assert (t.default_tracking is True)
    assert (t.local_tracking is None)
    assert (t.global_tracking is True)

    with pytest.raises(KeyError):
        assert (t.is_tracked("FOO"))

    t.global_tracking = False

    assert (t.default_tracking is False)

    with pytest.raises(KeyError):
        assert (not t.is_tracked("FOO"))

    with pytest.raises(KeyError):
        t.track_local("FOO")
def test_overlay():
    t = VariableTracking()
    t.local_tracking = False

    t.track_local("LOCAL_TRACKED")
    t.ignore_global("GLOBAL_IGNORED")

    assert (t.is_tracked("DEFAULT", "LOCAL_TRACKED",
                         "GLOBAL_IGNORED") == [False, True, False])

    t.global_tracking = False

    t.ignore_local("LOCAL_IGNORED")
    t.track_global("GLOBAL_TRACKED")

    assert (t.is_tracked(
        "DEFAULT", "LOCAL_TRACKED", "LOCAL_IGNORED", "GLOBAL_TRACKED",
        "GLOBAL_IGNORED") == [False, True, False, True, False])
def test_global():
    t = VariableTracking()
    t.ignore_global("FOO")
    assert (not t.is_explicitly_configured_local("FOO"))
    assert (t.is_explicitly_configured_global("FOO"))
    assert (not t.is_tracked("FOO"))

    t.unset_global("FOO")
    assert (not t.is_explicitly_configured_local("FOO"))
    assert (not t.is_explicitly_configured_global("FOO"))
    assert (t.is_tracked("FOO"))
def test_setup():
    t = VariableTracking()
    assert (t.is_tracked("FOO"))
Exemple #8
0
def test_track_uses_config_file(tmp_json):
    cfg = ConfigurationFile(tmp_json, VariableTracking.config_schema_global)
    vtr = VariableTracking(cfg, None)

    vtr.ignore_global("FOO")
    assert (not vtr.is_tracked("FOO"))
    assert (not vtr.is_explicitly_configured_local("FOO"))
    assert (vtr.is_explicitly_configured_global("FOO"))

    cfg.save()

    cfg2 = ConfigurationFile(tmp_json, VariableTracking.config_schema_local)
    vtr2 = VariableTracking(None, cfg2)
    assert (not vtr2.is_tracked("FOO"))
    assert (vtr2.is_explicitly_configured_local("FOO"))
    assert (not vtr2.is_explicitly_configured_global("FOO"))