8000 Test for redstone api · neumond/python-computer-craft@f9656fa · GitHub
[go: up one dir, main page]

Skip to content

Commit f9656fa

Browse files
committed
Test for redstone api
1 parent ffaea18 commit f9656fa

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

computercraft/subapis/colors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def __iter__(self):
4848
for c in self.chars.values():
4949
yield c
5050

51+
# combine, subtract and test are mostly for redstone.setBundledOutput
52+
5153
async def combine(self, *colors: int) -> int:
5254
return integer(await self._send('combine', *colors))
5355

computercraft/subapis/redstone.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ async def setAnalogOutput(self, side: str, strength: int):
2828
async def getAnalogOutput(self, side: str) -> int:
2929
return integer(await self._send('getAnalogOutput', side))
3030

31+
# bundled cables are not available in vanilla
32+
3133
async def getBundledInput(self, side: str) -> int:
3234
return integer(await self._send('getBundledInput', side))
3335

testmod.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,3 +851,56 @@ async def test_settings_api(api):
851851
await api.fs.delete('sfile')
852852

853853
await api.print('Test finished successfully')
854+
855+
856+
async def test_redstone_api(api):
857+
tbl = await get_object_table(api, 'redstone')
858+
859+
# remove British method names to make API lighter
860+
del tbl['function']['getAnalogueInput']
861+
del tbl['function']['getAnalogueOutput']
862+
del tbl['function']['setAnalogueOutput']
863+
864+
assert get_class_table(api.redstone.__class__) == tbl
865+
866+
assert set(await api.redstone.getSides()) == {'top', 'bottom', 'front', 'back', 'left', 'right'}
867+
868+
await step(api, 'Remove all the redstone from sides of computer')
869+
870+
side = 'top'
871+
872+
assert await api.redstone.setOutput(side, True) is None
873+
assert await api.redstone.getOutput(side) is True
874+
assert await api.redstone.getAnalogOutput(side) == 15
875+
assert await api.redstone.setOutput(side, False) is None
876+
assert await api.redstone.getOutput(side) is False
877+
assert await api.redstone.getAnalogOutput(side) == 0
878+
879+
assert await api.redstone.setAnalogOutput(side, 7) is None
880+
assert await api.redstone.getAnalogOutput(side) == 7
881+
assert await api.redstone.getOutput(side) is True
882+
assert await api.redstone.setAnalogOutput(side, 15) is None
883+
assert await api.redstone.getAnalogOutput(side) == 15
884+
assert await api.redstone.setAnalogOutput(side, 0) is None
885+
assert await api.redstone.getAnalogOutput(side) == 0
886+
assert await api.redstone.getOutput(side) is False
887+
888+
assert await api.redstone.getInput(side) is False
889+
assert await api.redstone.getAnalogInput(side) == 0
890+
891+
await step(api, f'Put redstone block on {side} side of computer')
892+
893+
assert await api.redstone.getInput(side) is True
894+
assert await api.redstone.getAnalogInput(side) > 0
895+
896+
await step(api, f'Remove redstone block\nPut piston on {side} side of computer')
897+
898+
assert await api.redstone.getInput(side) is False
899+
assert await api.redstone.getAnalogInput(side) == 0
900+
assert await api.redstone.setOutput(side, True) is None
901+
await asyncio.sleep(2)
902+
assert await api.redstone.setOutput(side, False) is None
903+
904+
await api.print('Piston must have been activated\nRemove piston')
905+
906+
await api.print('Test finished successfully')

0 commit comments

Comments
 (0)
0