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

winter-telescope / wintertoo / 5895014051

pending completion
5895014051

Pull #32

github

web-flow
Merge b20048a5a into d7d03dc17
Pull Request #32: Pydantic V2

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

329 of 430 relevant lines covered (76.51%)

0.77 hits per line

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

86.67
/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
1✔
8

9
from pydantic import BaseModel, ConfigDict, Field, FieldValidationInfo, field_validator
1✔
10

11

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

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

20

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

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

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

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

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

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

68
    model_config = ConfigDict(extra="forbid")
1✔
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