cterdam commited on
Commit
bdfdc53
·
verified ·
1 Parent(s): f896205

Update test to load from HF Hub

Browse files
Files changed (1) hide show
  1. test/test_invariants.py +10 -8
test/test_invariants.py CHANGED
@@ -2,14 +2,14 @@
2
  Invariant tests for cterdam/iata-metro dataset.
3
 
4
  Run from dataset root after cloning:
 
5
  pytest test/test_invariants.py -v
6
 
7
  Verifies:
8
  - name field matches lang selection (name_en/ru/zh)
9
  - hash = SHA256(name)
10
- - lang matches region's language rule
11
  - hash format is 64-char hex string
12
- - coordinates are valid (if present)
13
  """
14
 
15
  import hashlib
@@ -26,11 +26,11 @@ SINOPHONE_REGIONS = {
26
  }
27
 
28
 
29
- def determine_expected_lang(region: str) -> str:
30
  """Determine expected lang from region code."""
31
- if region in SINOPHONE_REGIONS:
32
  return 'zh'
33
- elif region in SLAVIC_REGIONS:
34
  return 'ru'
35
  else:
36
  return 'en'
@@ -38,7 +38,8 @@ def determine_expected_lang(region: str) -> str:
38
 
39
  @pytest.fixture(scope="session")
40
  def dataset():
41
- return load_dataset('.', split='train')
 
42
 
43
 
44
  def test_lang_values_valid(dataset):
@@ -114,7 +115,7 @@ def test_lang_matches_region(dataset):
114
  if len(mismatches) >= 5:
115
  break
116
 
117
- assert mismatches == [], f"Lang mismatches: {mismatches}"
118
 
119
 
120
  def test_coordinates_valid(dataset):
@@ -125,4 +126,5 @@ def test_coordinates_valid(dataset):
125
  if (e.get('lat') is not None and (e['lat'] < -90 or e['lat'] > 90)) or
126
  (e.get('lon') is not None and (e['lon'] < -180 or e['lon'] > 180))
127
  ]
128
- assert invalid == [], f"Invalid coordinates: {invalid[:5]}"
 
 
2
  Invariant tests for cterdam/iata-metro dataset.
3
 
4
  Run from dataset root after cloning:
5
+ pip install datasets pytest
6
  pytest test/test_invariants.py -v
7
 
8
  Verifies:
9
  - name field matches lang selection (name_en/ru/zh)
10
  - hash = SHA256(name)
11
+ - lang matches region-based language rule
12
  - hash format is 64-char hex string
 
13
  """
14
 
15
  import hashlib
 
26
  }
27
 
28
 
29
+ def determine_expected_lang(region_code: str) -> str:
30
  """Determine expected lang from region code."""
31
+ if region_code in SINOPHONE_REGIONS:
32
  return 'zh'
33
+ elif region_code in SLAVIC_REGIONS:
34
  return 'ru'
35
  else:
36
  return 'en'
 
38
 
39
  @pytest.fixture(scope="session")
40
  def dataset():
41
+ """Load dataset from HF Hub."""
42
+ return load_dataset('cterdam/iata-metro', split='train')
43
 
44
 
45
  def test_lang_values_valid(dataset):
 
115
  if len(mismatches) >= 5:
116
  break
117
 
118
+ assert mismatches == [], f"Lang mismatches: {{mismatches}}"
119
 
120
 
121
  def test_coordinates_valid(dataset):
 
126
  if (e.get('lat') is not None and (e['lat'] < -90 or e['lat'] > 90)) or
127
  (e.get('lon') is not None and (e['lon'] < -180 or e['lon'] > 180))
128
  ]
129
+ assert invalid == [], f"Invalid coordinates: {{invalid[:5]}}"
130
+