From dfd0b892b4d7eecd7e2bc1b093431443b475f75e Mon Sep 17 00:00:00 2001 From: Craig Thomas Date: Tue, 6 Aug 2019 22:18:35 -0400 Subject: [PATCH] Updated Travis requirements. Update packages installed during Travis run Remove ia32 libs from Travis. Remove trusty as default build platform. Add more CPU unit tests. Add release tag to README.md --- .travis.yml | 13 ++++++------- README.md | 1 + test/test_chip8cpu.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0e09d70..2150c0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python -dist: trusty -sudo: required +sudo: false python: - 2.7 env: @@ -19,16 +18,16 @@ addons: - libavformat-dev - libavcodec-dev - libjpeg-dev - - libtiff4-dev + - libtiff5-dev - libx11-6 - libx11-dev - xfonts-base - xfonts-100dpi - xfonts-75dpi -before_install: - - sudo apt-get update -qq - - sudo apt-get install libsmpeg-dev xfonts-cyrillic - - sh -e /etc/init.d/xvfb start + - libsmpeg-dev + - xfonts-cyrillic +services: + - xvfb virtalenv: system_site_packages: true script: diff --git a/README.md b/README.md index 88144a2..96b1d05 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Codecov](https://img.shields.io/codecov/c/gh/craigthomas/Chip8Python?style=flat-square)](https://codecov.io/gh/craigthomas/Chip8Python) [![Codacy Badge](https://img.shields.io/codacy/grade/f100b6deb9bf4729a2c55ef12fb695c9?style=flat-square)](https://www.codacy.com/app/craig-thomas/Chip8Python?utm_source=github.com&utm_medium=referral&utm_content=craigthomas/Chip8Python&utm_campaign=Badge_Grade) [![Dependencies](https://img.shields.io/librariesio/github/craigthomas/Chip8Python?style=flat-square)](https://libraries.io/github/craigthomas/Chip8Python) +[![Releases](https://img.shields.io/github/release/craigthomas/Chip8Python?style=flat-square)](https://github.com/craigthomas/Chip8Python/releases) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT) diff --git a/test/test_chip8cpu.py b/test/test_chip8cpu.py index 4e3ecd0..bb69711 100644 --- a/test/test_chip8cpu.py +++ b/test/test_chip8cpu.py @@ -9,6 +9,7 @@ import mock import pygame import unittest +import collections from mock import patch, call @@ -587,6 +588,13 @@ def test_execute_instruction_raises_exception_on_unknown_op_code_from_cpu(self): self.cpu.execute_instruction(operand=0x8008) self.assertEqual("Unknown op-code: 8008", context.exception.message) + def test_execute_instruction_on_operand_in_memory(self): + self.cpu.registers['pc'] = 0x200 + self.cpu.memory[0x200] = 0x61 + result = self.cpu.execute_instruction() + self.assertEqual(0x6100, result) + self.assertEqual(0x202, self.cpu.registers['pc']) + def test_execute_logical_instruction_raises_exception_on_unknown_op_codes(self): for x in xrange(8, 14): self.cpu.operand = x @@ -724,9 +732,43 @@ def test_load_index_with_sprite(self): self.cpu.load_index_with_extended_reg_sprite() self.assertEqual(100, self.cpu.registers['index']) + def test_str_function(self): + self.cpu.registers['v'][0] = 0 + self.cpu.registers['v'][1] = 1 + self.cpu.registers['v'][2] = 2 + self.cpu.registers['v'][3] = 3 + self.cpu.registers['v'][4] = 4 + self.cpu.registers['v'][5] = 5 + self.cpu.registers['v'][6] = 6 + self.cpu.registers['v'][7] = 7 + self.cpu.registers['v'][8] = 8 + self.cpu.registers['v'][9] = 9 + self.cpu.registers['v'][10] = 10 + self.cpu.registers['v'][11] = 11 + self.cpu.registers['v'][12] = 12 + self.cpu.registers['v'][13] = 13 + self.cpu.registers['v'][14] = 14 + self.cpu.registers['v'][15] = 15 + self.cpu.registers['pc'] = 0xBEEF + self.cpu.operand = 0xBA + self.cpu.registers['index'] = 0xDEAD + result = str(self.cpu) + self.assertEqual("PC: BEED OP: BA\nV0: 0\nV1: 1\nV2: 2\nV3: 3\nV4: 4\nV5: 5\nV6: 6\nV7: 7\nV8: 8\nV9: 9\nVA: A\nVB: B\nVC: C\nVD: D\nVE: E\nVF: F\nI: DEAD\n", result) + + def test_wait_for_keypress(self): + EventMock = collections.namedtuple('EventMock', 'type') + event_mock = EventMock(type=pygame.KEYDOWN) + self.cpu.operand = 0x0 + with mock.patch("pygame.event.wait", return_value=event_mock): + result_table = [False] * 512 + result_table[pygame.K_4] = True + with mock.patch("pygame.key.get_pressed", return_value=result_table): + self.cpu.wait_for_keypress() + self.assertEqual(0x1, self.cpu.registers['v'][0]) # M A I N ##################################################################### + if __name__ == '__main__': unittest.main()