Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ on:

jobs:
test:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install -U -r test-requirements.txt
- uses: actions/checkout@v7
- name: Set up uv
uses: astral-sh/setup-uv@v10.3.3
- name: Run tests
run: |
python -m pytest -v tests
run: uv run --locked pytest
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This repo contains all the info about Pyvo meetups in the Czech Republic.

[![Build Status](https://travis-ci.org/pyvec/pyvo-data.svg?branch=master)](https://travis-ci.org/pyvec/pyvo-data)
[![Build Status](https://github.com/pyvec/pyvo-data/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/pyvec/pyvo-data/actions/workflows/main.yml)

How to add an event
-------------------
Expand Down
4 changes: 3 additions & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ ignored_files:
- 'README'
- 'README.md'
- 'tests'
- 'test-requirements.txt'
- 'pyproject.toml'
- 'uv.lock'
- '.python-version'
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "pyvo-data"
version = "0"
description = "Data about Pyvo meetups in the Czech Republic"
requires-python = ">=3.14"
dependencies = []

[dependency-groups]
dev = [
"pytest>=8.3,<9",
"jsonschema>=4.23,<5",
"rfc3987>=1.3.8,<2",
"pyyaml>=6,<7",
"python-dateutil>=2.8,<3",
]

[tool.uv]
package = false

[tool.pytest.ini_options]
testpaths = ["tests"]
11 changes: 11 additions & 0 deletions schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ properties:
$ref: '#/definitions/location'
_source:
type: string
required:
- name
- location
venues:
type: object
additionalProperties: false
Expand Down Expand Up @@ -104,6 +107,8 @@ properties:
required:
- name
- city
- description
- organizer-info
events:
type: object
additionalProperties: false
Expand Down Expand Up @@ -193,8 +198,11 @@ properties:
type: string
required:
- name
- start
- city
- talks
required:
- series
meta:
type: object
additionalProperties: false
Expand Down Expand Up @@ -228,6 +236,9 @@ definitions:
$ref: '#/definitions/geo-coordinate'
longitude:
$ref: '#/definitions/geo-coordinate'
required:
- latitude
- longitude
string-translations:
type: object
additionalProperties: false
Expand Down
4 changes: 0 additions & 4 deletions test-requirements.txt

This file was deleted.

17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import copy

import pytest

from loader import load_data


@pytest.fixture(scope='session')
def loaded_data():
"""The whole data set, loaded once per test session. Do not mutate."""
return load_data()


@pytest.fixture
def data(loaded_data):
"""A private deep copy of the data set that a test may break at will"""
return copy.deepcopy(loaded_data)
49 changes: 49 additions & 0 deletions tests/loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Load the data directory into a dict, as the pyvo consumers do."""
import os
from pathlib import Path

import yaml

# The C loader is several times faster; fall back if libyaml is unavailable
YAML_LOADER = getattr(yaml, 'CSafeLoader', yaml.SafeLoader)


def dict_from_directory(directory, root, ignored_files=()):
"""Return the YAML files under root/directory as a nested dict.

Names in `ignored_files` (top level only) and dotfiles are skipped.
Each `*.yaml` file becomes an entry keyed by its name without the
extension, with `_source` set to its path relative to `root`.
Any other non-directory file raises ValueError.
"""
data = {}
for filename in sorted(os.listdir(os.path.join(root, directory))):
fullname = os.path.normpath(os.path.join(directory, filename))
absname = os.path.join(root, fullname)
if filename in ignored_files or filename.startswith('.'):
continue
if filename.endswith('.yaml'):
with open(absname) as f:
info = yaml.load(f, Loader=YAML_LOADER)
if not isinstance(info, dict):
raise ValueError(
f'{fullname}: expected a YAML mapping, '
f'got {type(info).__name__}')
info['_source'] = fullname
data[filename[:-len('.yaml')]] = info
elif os.path.isdir(absname):
data[filename] = dict_from_directory(fullname, root)
else:
raise ValueError('Unexpected file: ' + fullname)
return data


DATA_DIR = Path(__file__).resolve().parent.parent


def load_data():
"""Load the whole repository the way the consumers do (see meta.yaml)"""
with (DATA_DIR / 'meta.yaml').open() as f:
metadata = yaml.load(f, Loader=YAML_LOADER)
return dict_from_directory(
'.', DATA_DIR, ignored_files=metadata['ignored_files'])
14 changes: 0 additions & 14 deletions tests/test_load.py

This file was deleted.

47 changes: 47 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest

from loader import dict_from_directory


def test_yaml_files_get_source_and_key(tmp_path):
(tmp_path / 'a.yaml').write_text('x: 1\n')
data = dict_from_directory('.', tmp_path)
assert data == {'a': {'x': 1, '_source': 'a.yaml'}}


def test_nested_directories_become_nested_dicts(tmp_path):
(tmp_path / 'd').mkdir()
(tmp_path / 'd' / 'b.yaml').write_text('y: 2\n')
data = dict_from_directory('.', tmp_path)
assert data == {'d': {'b': {'y': 2, '_source': 'd/b.yaml'}}}


def test_ignored_names_and_dotfiles_skipped_at_top_level(tmp_path):
(tmp_path / 'README.md').write_text('hi')
(tmp_path / '.git').mkdir()
(tmp_path / '.git' / 'HEAD').write_text('ref')
(tmp_path / 'a.yaml').write_text('x: 1\n')
data = dict_from_directory('.', tmp_path, ignored_files=['README.md'])
assert list(data) == ['a']


def test_unexpected_file_raises(tmp_path):
(tmp_path / 'a').mkdir()
(tmp_path / 'a' / 'notes.txt').write_text('hi')
with pytest.raises(ValueError, match='Unexpected file'):
dict_from_directory('.', tmp_path)


def test_ignored_name_nested_in_subdirectory_still_raises(tmp_path):
(tmp_path / 'a').mkdir()
(tmp_path / 'a' / 'README.md').write_text('hi')
with pytest.raises(ValueError, match='Unexpected file'):
dict_from_directory('.', tmp_path, ignored_files=['README.md'])


@pytest.mark.parametrize('content', ['', '# only a comment\n', '- a\n- list\n'])
def test_yaml_file_that_is_not_a_mapping_names_the_file(tmp_path, content):
(tmp_path / 'd').mkdir()
(tmp_path / 'd' / 'bad.yaml').write_text(content)
with pytest.raises(ValueError, match=r'd/bad\.yaml.*mapping'):
dict_from_directory('.', tmp_path)
Loading