• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

winter-telescope / wintertoo / 5895052783

17 Aug 2023 07:20PM UTC coverage: 76.566%. First build
5895052783

Pull #32

github

robertdstein
py3.9
Pull Request #32: Pydantic V2

34 of 34 new or added lines in 3 files covered. (100.0%)

330 of 431 relevant lines covered (76.57%)

2.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.1
/wintertoo/models/program.py
1
"""
2
Base model for the program database
3

4
Duplicated (sorry) from mirar/pipelines/summer/models/program.py, to avoid
5
an elaborate web of imports for WSP.
6
"""
7
from datetime import date
3✔
8
from typing import Optional
3✔
9

10
from pydantic import BaseModel, ConfigDict, Field, FieldValidationInfo, field_validator
3✔
11

12

13
class ProgramCredentials(BaseModel):
3✔
14
    """
15
    Program credentials to access a program
16
    """
17

18
    progname: str = Field(min_length=8, max_length=8, example="2020A000")
3✔
19
    prog_key: str = Field()
3✔
20

21

22
class Program(ProgramCredentials):
3✔
23
    """
24
    A pydantic model for a program database entry
25
    """
26

27
    puid: Optional[int] = Field(default=None)
3✔
28
    progid: int = Field(default=1)
3✔
29
    pi_name: str = Field(min_length=1, example="Hubble", default=None)
3✔
30
    pi_email: str = Field(min_length=1, example="someone@institute.com", default=None)
3✔
31
    startdate: date = Field()
3✔
32
    enddate: date = Field()
3✔
33
    hours_allocated: float = Field(ge=0.0, default=None)
3✔
34
    hours_remaining: float = Field(ge=0.0, default=None)
3✔
35
    maxpriority: float = Field(description="Max priority")
3✔
36
    progtitle: str = Field(min_length=1, example="A program title", default=None)
3✔
37

38
    @field_validator("enddate")
3✔
39
    @classmethod
3✔
40
    def check_date(cls, enddate: date, info: FieldValidationInfo) -> date:
3✔
41
        """
42
        Ensure dates are correctly formatted
43

44
        :param enddate: end date
45
        :param info: field validation info
46
        :return: end date
47
        """
48
        startdate = info.data["startdate"]
3✔
49
        assert enddate > startdate
3✔
50
        return enddate
3✔
51

52
    @field_validator("hours_remaining")
3✔
53
    @classmethod
3✔
54
    def validate_time_allocation(
3✔
55
        cls, hours_remaining: float, info: FieldValidationInfo
56
    ) -> float:
57
        """
58
        Ensure that time remaining has a sensible value
59

60
        :param hours_remaining: hours remaining
61
        :param info: field validation info
62
        :return: field value
63
        """
64
        total_time = info.data["hours_allocated"]
×
65
        assert not hours_remaining > total_time
×
66
        assert not hours_remaining < 0.0
×
67
        return hours_remaining
×
68

69
    model_config = ConfigDict(extra="forbid")
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc