-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smoketesting of running main function
- Loading branch information
Showing
4 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""A fun number guessing game!""" | ||
|
||
import random | ||
|
||
def main(): | ||
number = random.randint(1, 100) | ||
guesses = 0 | ||
|
||
print("I'm thinking of a number, between 1 and 100. Can you guess what it is?") | ||
while True: | ||
guesses += 1 | ||
guess = input('= ') | ||
try: | ||
guess = int(guess) | ||
except ValueError: | ||
print("Base 10 integers only, please.") | ||
continue | ||
|
||
if guess > number: | ||
print("Too high!") | ||
elif guess < number: | ||
print("Too low!") | ||
else: | ||
print("That's right, {}. You got it in {} guesses.".format(number, guesses)) | ||
break | ||
|
||
print() | ||
input("Press enter to quit.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Application] | ||
name=Guess the Number | ||
version=1.0 | ||
entry_point=guessnumber:main | ||
# We need to set this to get a console: | ||
console=true | ||
|
||
[Python] | ||
version=3.6.3 | ||
bitness=64 | ||
format=bundled | ||
|
||
[Include] | ||
packages=guessnumber | ||
|
||
# This optional section adds a command which can be run from the Windows | ||
# command prompt. | ||
[Command guessnumber] | ||
entry_point=guessnumber:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import io | ||
from pathlib import Path | ||
import re | ||
import responses | ||
from shutil import copy | ||
from testpath import MockCommand, assert_isfile, assert_isdir | ||
from testpath.tempdir import TemporaryWorkingDirectory | ||
from zipfile import ZipFile | ||
|
||
from nsist import main | ||
from .utils import test_dir | ||
|
||
example_dir = Path(test_dir, 'console_example') | ||
|
||
def respond_python_zip(): | ||
buf = io.BytesIO() | ||
with ZipFile(buf, 'w') as zf: | ||
zf.writestr('python.exe', b'') | ||
return 200, {}, buf | ||
|
||
@responses.activate | ||
def test_console_example(): | ||
responses.add_callback('GET', re.compile(r'https://www.python.org/ftp/.*'), | ||
callback=respond_python_zip, content_type='application/zip', | ||
) | ||
|
||
with TemporaryWorkingDirectory() as td: | ||
for src in example_dir.iterdir(): | ||
copy(str(src), td) | ||
|
||
|
||
with MockCommand('makensis') as makensis: | ||
ec = main(['installer.cfg']) | ||
|
||
assert ec == 0 | ||
assert makensis.get_calls()[0]['argv'][1].endswith('installer.nsi') | ||
|
||
build_dir = Path(td, 'build', 'nsis') | ||
assert_isdir(build_dir) | ||
assert_isfile(build_dir / 'Python' / 'python.exe') | ||
assert_isfile(build_dir / 'pkgs' / 'guessnumber.py') | ||
assert_isfile(build_dir / 'Guess_the_Number.launch.py') |