# Path: i3configger/config.py
# class MARK:
# class I3configgerConfig:
#     COMMENT = "#"
#     SET = "set"
#     VAR = "$"
# SUFFIX = ".conf"
# I3BAR = "i3bar"
# DEFAULTS = {
#     "main": {
#         "target": "../config",
#         "i3_refresh_msg": "reload",
#         "status_command": "i3status",
#         "log": None,
#         "notify": False,
#     },
#     "bars": {
#         "defaults": {"template": "tpl", "target": "..", "select": "default"},
#         "targets": {},
#     },
# }
# CONFIG_CANDIDATES = [
#     Path("~/.i3").expanduser(),
#     Path(os.getenv("XDG_CONFIG_HOME", "~/.config/")).expanduser() / "i3",
# ]
#     PARTIALS_NAME = "config.d"
#     CONFIG_NAME = "i3configger.json"
#     MESSAGES_NAME = ".messages.json"
#     def __init__(self, load=True):
#     def __str__(self):
#     def load(self):
#     def get_bar_targets(self):
# def fetch(path: Path) -> dict:
# def freeze(path, obj):
# def ensure_i3_configger_sanity():
# def get_i3wm_config_path():
# 
# Path: i3configger/build.py
# def persist_results(pathContentsMap):
#     for path, content in pathContentsMap.items():
#         backupPath = Path(str(path) + ".bak")
#         if path.exists() and not backupPath.exists():
#             path.rename(backupPath)
#         path.write_text(content)


import json
from pathlib import Path
from i3configger import config
from i3configger.build import persist_results



def test_initialization(tmp_path, monkeypatch):
    """Given empty sources directory a new config is created from defaults"""
    monkeypatch.setattr(config, "get_i3wm_config_path", lambda: tmp_path)
    assert not (tmp_path / "config.d").exists()
    config.ensure_i3_configger_sanity()

# Path: i3configger/config.py
# class MARK:
# class I3configgerConfig:
#     COMMENT = "#"
#     SET = "set"
#     VAR = "$"
# SUFFIX = ".conf"
# I3BAR = "i3bar"
# DEFAULTS = {
#     "main": {
#         "target": "../config",
#         "i3_refresh_msg": "reload",
#         "status_command": "i3status",
#         "log": None,
#         "notify": False,
#     },
#     "bars": {
#         "defaults": {"template": "tpl", "target": "..", "select": "default"},
#         "targets": {},
#     },
# }
# CONFIG_CANDIDATES = [
#     Path("~/.i3").expanduser(),
#     Path(os.getenv("XDG_CONFIG_HOME", "~/.config/")).expanduser() / "i3",
# ]
#     PARTIALS_NAME = "config.d"
#     CONFIG_NAME = "i3configger.json"
#     MESSAGES_NAME = ".messages.json"
#     def __init__(self, load=True):
#     def __str__(self):
#     def load(self):
#     def get_bar_targets(self):
# def fetch(path: Path) -> dict:
# def freeze(path, obj):
# def ensure_i3_configger_sanity():
# def get_i3wm_config_path():
# 
# Path: i3configger/build.py
# def persist_results(pathContentsMap):
#     for path, content in pathContentsMap.items():
#         backupPath = Path(str(path) + ".bak")
#         if path.exists() and not backupPath.exists():
#             path.rename(backupPath)
#         path.write_text(content)


# Path: tests/test_config.py
import json
from pathlib import Path
from i3configger import config
from i3configger.build import persist_results




def test_initialization(tmp_path, monkeypatch):
    """Given empty sources directory a new config is created from defaults"""
    monkeypatch.setattr(config, "get_i3wm_config_path", lambda: tmp_path)
    assert not (tmp_path / "config.d").exists()
    config.ensure_i3_configger_sanity()

    cnf = config.I3configgerConfig()