Skip to content

Instantly share code, notes, and snippets.

@ColdGrub1384
Created June 2, 2020 03:02
Show Gist options
  • Save ColdGrub1384/e847a18a2e31e6a1f9ed264842818568 to your computer and use it in GitHub Desktop.
Save ColdGrub1384/e847a18a2e31e6a1f9ed264842818568 to your computer and use it in GitHub Desktop.
Pyto Basic Unit Tests
"""
Tests for Pyto before submitting to the App Store.
"""
import unittest
import runpy
import sys
from apps import Shortcuts
shortcuts = Shortcuts()
class TestPyto(unittest.TestCase):
def test_lib(self):
from Lib import (apps, location, mainthread, motion,
multipeer, music, notification_center, notifications,
pasteboard, photos, pyto_core, pyto_ui,
remote_notifications, sharing, sound, speech, userkeys,
xcallback)
def test_modules(self):
runpy.run_module("download_all")
def test_pip(self):
import pip
pip.main(["install", "sympy"])
import sympy
pip.main(["uninstall", "sympy"])
def test_command_runner(self):
expected_result = "usage: pip.py [-h] [--verbose] [-6]\n sub-command ...\npip.py: error: argument sub-command: invalid choice: '—-help' (choose from 'list', 'install', 'download', 'search', 'versions', 'uninstall', 'update')"
out = open("out.txt", "w+")
_out = sys.stdout
_err = sys.stderr
sys.stdout = out
sys.stderr = out
sys.argv = ["pyto", "pip", "—-help"]
runpy.run_module("command_runner")
sys.stdout = _out
sys.stderr = _err
out.close()
out = open("out.txt", "r")
res = out.read()
out.close()
res = res.replace(" ", "")
res = res.replace("\n", "")
res = res.replace("\t", "")
expected_result = expected_result.replace(" ", "")
expected_result = expected_result.replace("\n", "")
expected_result = expected_result.replace("\t", "")
self.assertEqual(res, expected_result)
if __name__ == '__main__':
try:
unittest.main()
except SystemExit:
pass
shortcuts.open_shortcuts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment