File: unit_test.py

package info (click to toggle)
lightyears 1.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,804 kB
  • sloc: python: 5,532; sh: 39; makefile: 6
file content (103 lines) | stat: -rw-r--r-- 3,307 bytes parent folder | download | duplicates (2)
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
#
# 20,000 Light Years Into Space
# This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-21.
#

import os, pygame, pickle
from lib20k import game_random, game, save_game, resource, config
from lib20k import events, menu, main, mail, map_items, network, grid, quiet_season
from lib20k.ui import User_Interface
from lib20k.primitives import *
from lib20k.game_types import *


def Setup_For_Unit_Test() -> SurfaceType:
    resource.DATA_DIR = os.path.join(os.getcwd(), "data")
    pygame.init()
    pygame.font.init()
    config.cfg.mute = True
    resource.Initialise()
    mail.Set_Screen_Height(MINIMUM_HEIGHT)
    return pygame.display.set_mode((MINIMUM_WIDTH, MINIMUM_HEIGHT), pygame.RESIZABLE)

class Click(events.Event):
    def __init__(self, pos: SurfacePosition) -> None:
        events.Event.__init__(self, pos=pos,
                              t=pygame.MOUSEBUTTONDOWN, button=1)

class RightClick(events.Event):
    def __init__(self, pos: SurfacePosition) -> None:
        events.Event.__init__(self, pos=pos,
                              t=pygame.MOUSEBUTTONDOWN, button=2)

class Release(events.Event):
    def __init__(self, pos: SurfacePosition) -> None:
        events.Event.__init__(self, pos=pos,
                              t=pygame.MOUSEBUTTONUP, button=1)

class Move(events.Event):
    def __init__(self, pos: SurfacePosition) -> None:
        events.Event.__init__(self, pos=pos, t=pygame.MOUSEMOTION)

class Push(events.Event):
    def __init__(self, key: int) -> None:
        events.Event.__init__(self, key=key, t=pygame.KEYDOWN)

class Other(events.Event):
    def __init__(self) -> None:
        events.Event.__init__(self, t=pygame.KEYUP)

class Quit(events.Event):
    def __init__(self) -> None:
        events.Event.__init__(self, t=pygame.QUIT)

class VideoResize(events.Event):
    def __init__(self) -> None:
        events.Event.__init__(self, t=pygame.VIDEORESIZE)

class ActiveEvent(events.Event):
    def __init__(self) -> None:
        events.Event.__init__(self, t=pygame.ACTIVEEVENT)

class NoEvent(events.Event):
    pass

class Screenshot(NoEvent):
    def __init__(self, output: str) -> None:
        events.Event.__init__(self, t=pygame.NOEVENT)
        self.output = output

    def trigger(self) -> None:
        pygame.image.save(pygame.display.get_surface(), os.path.join("tmp", self.output))

class Fake_Events(events.Events):
    def __init__(self, event_list: List[events.Event]) -> None:
        events.Events.__init__(self)
        self.event_list = event_list
        self.index = 0
        self.is_testing = True

    def real_poll(self) -> None:
        e = pygame.event.poll()
        while e.type != pygame.NOEVENT:
            e = pygame.event.poll()

    def wait(self) -> events.Event:
        self.real_poll()
        return self.poll()

    def poll(self) -> events.Event:
        self.real_poll()
        assert self.index < len(self.event_list)
        self.index += 1
        event = self.event_list[self.index - 1]
        if isinstance(event, Screenshot):
            event.trigger()
        return event

    def webbrowser_open(self, url: str) -> None:
        mail.New_Mail("OPEN URL " + url)

    def check_update(self, url: str) -> str:
        mail.New_Mail("CHECK UPDATE URL " + url)
        return "9.9"