File size: 3,772 Bytes
8429e5e
 
 
 
 
ad8201c
8429e5e
 
 
 
 
 
 
 
 
 
 
61f1033
8429e5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61f1033
8429e5e
 
 
 
 
 
 
 
61f1033
8429e5e
 
 
 
 
 
 
 
 
 
61f1033
8429e5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""Tests for gazet.config — data path resolution and environment overrides."""

import os
from pathlib import Path

from gazet import config


class TestPreferNormalized:
    def test_prefers_normalized_when_exists(self, tmp_path, monkeypatch):
        monkeypatch.setenv("GAZET_USE_NORMALIZED_DATA", "1")
        norm_dir = tmp_path / "normalized"
        norm_dir.mkdir()
        (norm_dir / "test.parquet").touch()
        orig = tmp_path / "original.parquet"
        orig.touch()

        result = config._prefer_normalized(norm_dir / "test.parquet", orig)
        assert result == norm_dir / "test.parquet"

    def test_falls_back_to_original_when_normalized_missing(self, tmp_path):
        norm = tmp_path / "normalized.parquet"  # doesn't exist
        orig = tmp_path / "original.parquet"
        orig.touch()

        result = config._prefer_normalized(norm, orig)
        assert result == orig

    def test_wildcard_normalized_when_glob_matches(self, tmp_path, monkeypatch):
        monkeypatch.setenv("GAZET_USE_NORMALIZED_DATA", "1")
        norm_dir = tmp_path / "normalized"
        norm_dir.mkdir()
        (norm_dir / "data.parquet").touch()
        orig = tmp_path / "original.parquet"
        orig.touch()

        result = config._prefer_normalized(norm_dir / "*.parquet", orig)
        assert result == norm_dir / "*.parquet"

    def test_wildcard_falls_back_when_no_match(self, tmp_path):
        norm_dir = tmp_path / "empty"
        norm_dir.mkdir()
        orig = tmp_path / "original.parquet"
        orig.touch()

        result = config._prefer_normalized(norm_dir / "*.parquet", orig)
        assert result == orig

    def test_respects_use_normalized_off(self, tmp_path, monkeypatch):
        monkeypatch.setenv("GAZET_USE_NORMALIZED_DATA", "0")
        norm_dir = tmp_path / "normalized"
        norm_dir.mkdir()
        (norm_dir / "test.parquet").touch()
        orig = tmp_path / "original.parquet"
        orig.touch()

        result = config._prefer_normalized(norm_dir / "test.parquet", orig)
        # Should fall back because GAZET_USE_NORMALIZED_DATA is "0"
        assert result == orig


class TestDataDir:
    def test_data_dir_resolves(self):
        # _DATA_DIR should be set (either from env or relative to this file)
        assert isinstance(config._DATA_DIR, Path)
        assert config._DATA_DIR.exists()

    def test_divisions_path_is_set(self):
        assert config.DIVISIONS_AREA_PATH
        assert "divisions_area" in config.DIVISIONS_AREA_PATH

    def test_natural_earth_path_is_set(self):
        assert config.NATURAL_EARTH_PATH
        assert "natural_earth" in config.NATURAL_EARTH_PATH


class TestSchemaInfo:
    def test_schema_info_mentions_divisions_area(self):
        assert "divisions_area" in config.SCHEMA_INFO

    def test_schema_info_mentions_natural_earth(self):
        assert "natural_earth" in config.SCHEMA_INFO

    def test_schema_info_mentions_st_asgeojson(self):
        assert "ST_AsGeoJSON" in config.SCHEMA_INFO

    def test_schema_info_mentions_geometry(self):
        assert "geometry" in config.SCHEMA_INFO


class TestLlamaConfig:
    def test_llama_server_url_default(self):
        assert config.LLAMA_SERVER_URL == "http://localhost:9000"

    def test_llama_server_url_env(self, monkeypatch):
        monkeypatch.setenv("LLAMA_SERVER_URL", "http://remote:8080")
        # Reimport to pick up env var — config is module-level, so we
        # need to check the env var directly since module is already loaded.
        assert os.environ["LLAMA_SERVER_URL"] == "http://remote:8080"

    def test_llama_max_tokens_default(self):
        assert config.LLAMA_MAX_TOKENS == 2048

    def test_llama_temperature_default(self):
        assert config.LLAMA_TEMPERATURE == 0.0