Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test harness update #81

Merged
merged 5 commits into from Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci-lite.off
Expand Up @@ -9,7 +9,7 @@ jobs:
# Install & Test
# Set up environment
# Test
# Run tests/tests.py
# Run tests
install-test:
name: Install/Test
# cycle through os list
Expand Down Expand Up @@ -45,10 +45,10 @@ jobs:
geom=640x480x24
exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log &
export DISPLAY=:99
python ./tests/tests.py
python -m unittest
if: contains(matrix.os-name, 'windows') != true
- name: Start virtual display driver & Test (windows)
uses: GabrielBB/xvfb-action@v1
with:
run: python ./tests/tests.py
run: python -m unittest
if: contains(matrix.os-name, 'windows')
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -15,7 +15,7 @@ on: [ push, pull_request ]
# Halt if fail
# Define Tests Job
# Calls Install Job
# Run tests.py
# Run tests
# Halt if fail
# Define Build Job
# Calls Install Job
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
# Install & Test
# Set up environment
# Test
# Run tests/tests.py
# Run python -m unittest
install-test:
name: Install/Test
# cycle through os list
Expand Down Expand Up @@ -80,12 +80,12 @@ jobs:
geom=640x480x24
exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log &
export DISPLAY=:99
python ./tests/tests.py
python -m unittest
if: contains(matrix.os-name, 'windows') != true
- name: Start virtual display driver & Test (windows)
uses: GabrielBB/xvfb-action@v1
with:
run: python ./tests/tests.py
run: python -m unittest
if: contains(matrix.os-name, 'windows')
# Install & Build
# Set up environment
Expand Down
2 changes: 1 addition & 1 deletion .travis.off
Expand Up @@ -51,7 +51,7 @@ jobs:
# 6 Step
before_script: echo "#do nothing before script"
# 7 Step
script: ${PYTHON_EXECUTABLE} ./tests/tests.py
script: ${PYTHON_EXECUTABLE} -m unittest

# 3.7 on Bionic Build/Deploy
- &build-deploy
Expand Down
8 changes: 8 additions & 0 deletions tests/README.md
Expand Up @@ -3,3 +3,11 @@
## Unit Tests

A battery of tests with the goal to ensure that any changes made will not hopefully pooch the entire project. These have a long way to go to test all of the things since we keep adding new toys to the interface.

Legacy = Tests implemented before refactor, but have not yet been updated to the new testing framework

Units = Tests of a specific class or module only
Integration = Tests of how classes/modules work together
System = Top level tests that simulate the user experience

Resources = Files needed to help determine if the tests work (e.g. test images)
3 changes: 2 additions & 1 deletion tests/__init__.py
@@ -1 +1,2 @@
#do nothing, just exist to make "tests" package
#this file exists to notify python to execute tests here
#should be blank otherwise
2 changes: 2 additions & 0 deletions tests/integration/__init__.py
@@ -0,0 +1,2 @@
#this file exists to notify python to execute tests here
#should be blank otherwise
2 changes: 2 additions & 0 deletions tests/legacy/__init__.py
@@ -0,0 +1,2 @@
#this file exists to notify python to execute tests here
#should be blank otherwise
File renamed without changes.
49 changes: 49 additions & 0 deletions tests/legacy/legacy_gc.py
@@ -0,0 +1,49 @@
#GARBAGE COLLECTION TESTS
#this file should contain tests that probe for memory leaks and any other mismanagement of RAM

from tests.legacy.common_vars import * #contains utilities common to all tests. Should come first before the other imports.

import unittest #for unit testing, har har
import os #for path.join and similar, to find the files we want to audit

#this next class is inspired by a suggestion from Fry: https://www.youtube.com/watch?v=1Isjgc0oX0s
class NoMemoryLeaks(unittest.TestCase):
def setUp(self):
import tkinter as tk
import weakref #we weakref something to see if it was garbage collected

self.pseudo_root = tk.Tk() #make a pseudo GUI environment

def test_sprites_and_games_are_destroyed(self):
from source.meta.gui import gui
#make the GUI in skeleton form (no looping)
pseudo_command_line_args = {"sprite": LINK_FILENAME}

self.pseudo_root.withdraw() #make the pseudo GUI invisible
GUI_skeleton = gui.SpriteSomethingMainFrame(self.pseudo_root, pseudo_command_line_args)

#save a weakref to the old sprite
old_sprite_ref = weakref.ref(GUI_skeleton.sprite)
old_game_ref = weakref.ref(GUI_skeleton.game)
old_animation_engine_ref = weakref.ref(GUI_skeleton.animation_engine)

#try to load a new sprite
GUI_skeleton.load_sprite(SAMUS_FILENAME)

#see if the old classes were garbage collected
self.assertTrue(old_sprite_ref() is None)
self.assertTrue(old_game_ref() is None)
self.assertTrue(old_animation_engine_ref() is None)

#now go the other way around and test going to Zelda3 from Metroid3
old_sprite_ref = weakref.ref(GUI_skeleton.sprite)
old_game_ref = weakref.ref(GUI_skeleton.game)
old_animation_engine_ref = weakref.ref(GUI_skeleton.animation_engine)
GUI_skeleton.load_sprite(LINK_FILENAME)
self.assertTrue(old_sprite_ref() is None)
self.assertTrue(old_game_ref() is None)
self.assertTrue(old_animation_engine_ref() is None)


if __name__ == '__main__':
unittest.main()
Expand Up @@ -3,7 +3,7 @@
#
#in general, these tests should be testing the import framework

from test_common import * #contains utilities common to all tests. Should come first before the other imports.
from tests.legacy.common_vars import * #contains utilities common to all tests. Should come first before the other imports.

import unittest #for unit testing, har har
import sys #so that we can check to see which modules are imported at any given time
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asserts.py → tests/legacy/test_asserts.py
Expand Up @@ -5,7 +5,7 @@
#The intention is that most unit tests will go here, excepting the ones that do not play well with the others,
# which at the time of writing this comment, are the tests for memory leaks and stray imports (test_gc.py and test_waterfalls.py)

from test_common import * #contains utilities common to all tests. Should come first before the other imports.
from tests.legacy.common_vars import * #contains utilities common to all tests. Should come first before the other imports.

import unittest #for unit testing, har har
import json #need to audit our json files
Expand Down
2 changes: 2 additions & 0 deletions tests/system/__init__.py
@@ -0,0 +1,2 @@
#this file exists to notify python to execute tests here
#should be blank otherwise
50 changes: 0 additions & 50 deletions tests/test_gc.py

This file was deleted.

19 changes: 0 additions & 19 deletions tests/tests.py

This file was deleted.

2 changes: 2 additions & 0 deletions tests/units/__init__.py
@@ -0,0 +1,2 @@
#this file exists to notify python to execute tests here
#should be blank otherwise