Skip to content

Commit

Permalink
Cleanup namespace handling in tests (#100)
Browse files Browse the repository at this point in the history
* Cleanup namespace handling in tests

When we did a lot of recent Python2-isms cleanup recently
it broke some tests when run in an environment where a
previous version of paste, or one of the consumers of its
namespace package, were already installed.

This was probably done to quiet warnings. However, it
hides issues with complex environments.

In addition to fixing the problem, this change adds a
tox test environment that should cause a failure if
we introduce the error again.

Fixes #99

* remove skipsdist to see if that ensures namespace

* update LICENSE per #101
  • Loading branch information
cdent authored May 1, 2024
1 parent 4926cdf commit 13dc956
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
env: py310
- python: "3.11"
env: py311
- python: "3.11"
env: py311-namespace
- python: "3.12"
env: py312
- python: pypy-3.10
Expand Down
1 change: 1 addition & 0 deletions LICENSE
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include docs/conf.py
include docs/test_server.ini
include regen-docs
include tox.ini
include LICENSE
recursive-exclude docs/_build/_sources *
recursive-include docs/_build *.html
recursive-include tests *.txt *.py *.cgi *.html
Expand Down
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
"""Tests for Paste"""
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import pkg_resources
11 changes: 10 additions & 1 deletion tests/cgiapp_data/form.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ print('Content-type: text/plain')
print('')

import sys
import warnings
from os.path import dirname

base_dir = dirname(dirname(dirname(__file__)))
sys.path.insert(0, base_dir)

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
try:
import pkg_resources
except ImportError:
# Ignore
pass

from paste.util.field_storage import FieldStorage

class FormFieldStorage(FieldStorage):
Expand Down Expand Up @@ -52,7 +61,7 @@ class FormFieldStorage(FieldStorage):
return False


form = FieldStorage()
form = FormFieldStorage()

print('Filename:', form['up'].filename)
print('Name:', form['name'].value)
Expand Down
20 changes: 17 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
[tox]
envlist = py{36, 37, 38, 39, 310, 311, 312, py}
envlist = py{36, 37, 38, 39, 310, 311, 312, py},py311-namespace

[base]
deps =
pytest
setuptools

[testenv]
# For performance, but also for using "source" with coveragepy (https://github.com/nedbat/coveragepy/issues/268).
usedevelop = True
deps =
pytest
{[base]deps}
coverage: coverage
coverage: pytest-cov
setenv =
coverage: PYTEST_ADDOPTS=--cov --cov-report=term-missing
commands =
pytest {posargs}
python -m pytest {posargs}

# Test an environment where paste, pastedeploy and pastescript are already
# installed.
[testenv:py311-namespace]
deps =
{[base]deps}
Paste==3.9.0
PasteDeploy
pastescript

1 comment on commit 13dc956

@kim-a11y
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import pygame
import random

pygame.init()

Variabel layar

screen_width = 800
screen_height = 600
cell_size = 20
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Snake Game")

Warna yang digunakan

black = (0, 0, 0)
white = (255, 255, 255)
green = (0, 255, 0)

Fungsi tampilan teks

def print_text(message, color, x, y, font_size):
font = pygame.font.SysFont(None, font_size)
text = font.render(message, True, color)
screen.blit(text, (x, y))

Fungsi utama game

def game():
snake = [[screen_width // 2, screen_height // 2]]
snake_dir = [0, 0]
food_pos = [random.randint(0, screen_width // cell_size - 1) * cell_size,
random.randint(0, screen_height // cell_size - 1) * cell_size]

clock = pygame.time.Clock()
running = True

while running:
    screen.fill(black)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    keys = pygame.key.get_pressed()
    if keys[pygame.K_UP]:
        snake_dir = [0, -cell_size]
    if keys[pygame.K_DOWN]:
        snake_dir = [0, cell_size]
    if keys[pygame.K_LEFT]:
        snake_dir = [-cell_size, 0]
    if keys[pygame.K_RIGHT]:
        snake_dir = [cell_size, 0]

    snake[0][0] += snake_dir[0]
    snake[0][1] += snake_dir[1]

    if snake[0] == food_pos:
        snake.append([0, 0])
        food_pos = [random.randint(0, screen_width // cell_size - 1) * cell_size,
                    random.randint(0, screen_height // cell_size - 1) * cell_size]

    for i, segment in enumerate(snake):
        pygame.draw.rect(screen, green, pygame.Rect(segment[0], segment[1], cell_size, cell_size))

    pygame.draw.rect(screen, white, pygame.Rect(food_pos[0], food_pos[1], cell_size, cell_size))

    if snake[0][0] < 0 or snake[0][0] >= screen_width or snake[0][1] < 0 or snake[0][1] >= screen_height:
        running = False

    pygame.display.flip()
    clock.tick(10)

pygame.quit()

Memulai game

game()

Please sign in to comment.