|
| 1 | +R671:0[5]{:[1]<9>pocket.py:[0]<2>py}<9>pocket.py<623>from cc import LuaException, import_file, pocket, peripheral |
| 2 | + |
| 3 | +_lib = import_file('_lib.py', __file__) |
| 4 | + |
| 5 | + |
| 6 | +assert peripheral.isPresent('back') is False |
| 7 | + |
| 8 | +_lib.step('Clean inventory from any pocket upgrades') |
| 9 | + |
| 10 | +with _lib.assert_raises(LuaException): |
| 11 | + pocket.equipBack() |
| 12 | +with _lib.assert_raises(LuaException): |
| 13 | + pocket.unequipBack() |
| 14 | +assert peripheral.isPresent('back') is False |
| 15 | + |
| 16 | +_lib.step('Put any pocket upgrade to inventory') |
| 17 | + |
| 18 | +assert pocket.equipBack() is None |
| 19 | +assert peripheral.isPresent('back') is True |
| 20 | + |
| 21 | +assert pocket.unequipBack() is None |
| 22 | +assert peripheral.isPresent('back') is False |
| 23 | + |
| 24 | +print('Test finished successfully') |
| 25 | +S257:T<1>1<215>local p, rel = ... |
| 26 | +if rel ~= nil then |
| 27 | +p = fs.combine(fs.getDir(rel), p) |
| 28 | +end |
| 29 | +if not fs.exists(p) then return nil end |
| 30 | +if fs.isDir(p) then return nil end |
| 31 | +f = fs.open(p, "r") |
| 32 | +local src = f.readAll() |
| 33 | +f.close() |
| 34 | +return src{:[1]<7>_lib.py:[2]<9>pocket.py} |
| 35 | +R1162:T<1>1<1151>{:[1]T:[2]<1134>from contextlib import contextmanager |
| 36 | +from cc import os |
| 37 | + |
| 38 | + |
| 39 | +@contextmanager |
| 40 | +def assert_raises(etype, message=None): |
| 41 | + try: |
| 42 | + yield |
| 43 | + except Exception as e: |
| 44 | + assert isinstance(e, etype), repr(e) |
| 45 | + if message is not None: |
| 46 | + assert e.args == (message, ) |
| 47 | + else: |
| 48 | + raise AssertionError(f'Exception of type {etype} was not raised') |
| 49 | + |
| 50 | + |
| 51 | +@contextmanager |
| 52 | +def assert_takes_time(at_least, at_most): |
| 53 | + t = os.epoch('utc') / 1000 |
| 54 | + yield |
| 55 | + dt = os.epoch('utc') / 1000 - t |
| 56 | + # print(at_least, '<=', dt, '<=', at_most) |
| 57 | + assert at_least <= dt <= at_most |
| 58 | + |
| 59 | + |
| 60 | +class AnyInstanceOf: |
| 61 | + def __init__(self, cls): |
| 62 | + self.c = cls |
| 63 | + |
| 64 | + def __eq__(self, other): |
| 65 | + return isinstance(other, self.c) |
| 66 | + |
| 67 | + |
| 68 | +def step(text): |
| 69 | + input(f'{text} [enter]') |
| 70 | + |
| 71 | + |
| 72 | +def term_step(text): |
| 73 | + from cc import colors, term |
| 74 | + |
| 75 | + for color in colors.iter_colors(): |
| 76 | + r, g, b = term.nativePaletteColor(color) |
| 77 | + term.setPaletteColor(color, r, g, b) |
| 78 | + term.setBackgroundColor(colors.black) |
| 79 | + term.setTextColor(colors.white) |
| 80 | + term.clear() |
| 81 | + term.setCursorPos(1, 1) |
| 82 | + term.setCursorBlink(True) |
| 83 | + step(text)} |
| 84 | +S46:T<1>1<24>G:peripheral:M:isPresent{:[1]<4>back} |
| 85 | +R21:T<1>1<12>{:[1]T:[2]F} |
| 86 | +S80:T<1>1<13>io.write(...){:[1]<48>Clean inventory from any pocket upgrades [enter]} |
| 87 | +R15:T<1>1<7>{:[1]T} |
| 88 | +S22:T<1>1<11>G:io:M:read{} |
| 89 | +R23:T<1>1<14>{:[1]T:[2]<0>} |
| 90 | +S31:T<1>1<20>G:pocket:M:equipBack{} |
| 91 | +R56:T<1>1<47>{:[1]T:[2]F:[3]<27>Cannot find a valid upgrade} |
| 92 | +S33:T<1>1<22>G:pocket:M:unequipBack{} |
| 93 | +R47:T<1>1<38>{:[1]T:[2]F:[3]<18>Nothing to unequip} |
| 94 | +S46:T<1>1<24>G:peripheral:M:isPresent{:[1]<4>back} |
| 95 | +R21:T<1>1<12>{:[1]T:[2]F} |
| 96 | +S75:T<1>1<13>io.write(...){:[1]<43>Put any pocket upgrade to inventory [enter]} |
| 97 | +R15:T<1>1<7>{:[1]T} |
| 98 | +S22:T<1>1<11>G:io:M:read{} |
| 99 | +R23:T<1>1<14>{:[1]T:[2]<0>} |
| 100 | +S31:T<1>1<20>G:pocket:M:equipBack{} |
| 101 | +R21:T<1>1<12>{:[1]T:[2]T} |
| 102 | +S46:T<1>1<24>G:peripheral:M:isPresent{:[1]<4>back} |
| 103 | +R21:T<1>1<12>{:[1]T:[2]T} |
| 104 | +S33:T<1>1<22>G:pocket:M:unequipBack{} |
| 105 | +R21:T<1>1<12>{:[1]T:[2]T} |
| 106 | +S46:T<1>1<24>G:peripheral:M:isPresent{:[1]<4>back} |
| 107 | +R21:T<1>1<12>{:[1]T:[2]F} |
| 108 | +S58:T<1>1<13>io.write(...){:[1]<26>Test finished successfully} |
| 109 | +R15:T<1>1<7>{:[1]T} |
| 110 | +S32:T<1>1<13>io.write(...){:[1]<1> |
| 111 | +} |
| 112 | +R15:T<1>1<7>{:[1]T} |
| 113 | +S2:CN |
0 commit comments