Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Fixed test file path references, and added teardown method
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmundGoodman committed Oct 30, 2021
1 parent 9600d98 commit 72dae02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ignore:
- "jupylint/test_files/*" # Don't test coverage on sample Jupyter notebooks
- "jupylint/_test_template.py" # Don't test the test template file
- "jupylint/__main__.py" # Don't test the __main__ packaging method
- "setup.py" # Don't test the PyPI upload setup file
20 changes: 13 additions & 7 deletions jupylint/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from subprocess import check_output, CalledProcessError, STDOUT
from os import path
from os import path, remove
import unittest

from .jupylint import Jupylint
Expand Down Expand Up @@ -77,45 +77,51 @@ def test_ugly_code(self):
def test_no_params(self):
"""Check that running with no parameters fails"""
result = get_jupylint_output(
"python3 ./jupylint/jupylint.py".split(" ")
"python3 ./jupylint_runner.py".split(" ")
)
self.assertTrue("error" in result)

def test_params_input_file_valid(self):
"""Check that running with a valid input file works"""
result = get_jupylint_output(
"python3 ./jupylint/jupylint.py ./jupylint/test_files/stylish.ipynb".split(" ")
"python3 ./jupylint_runner.py ./jupylint/test_files/stylish.ipynb".split(" ")
)
self.assertTrue("Your code has been rated" in result)

def test_params_input_file_not_found(self):
"""Check that running with an invalid input file fails"""
result = get_jupylint_output(
"python3 ./jupylint/jupylint.py ./jupylint/test_files/non_existent_file.ipynb".split(" ")
"python3 ./jupylint_runner.py ./jupylint/test_files/non_existent_file.ipynb".split(" ")
)
self.assertEqual("Input file cannot be found\n", result)

def test_params_output_file(self):
"""Check that running with a valid output file works"""
result = get_jupylint_output(
"python3 ./jupylint/jupylint.py ./jupylint/test_files/stylish.ipynb ./out.py".split(" ")
"python3 ./jupylint_runner.py ./jupylint/test_files/stylish.ipynb ./out.py".split(" ")
)
self.assertTrue("Your code has been rated" in result)

def test_keep_code_file_default(self):
"""Check that running without the keep flag deletes the file"""
_ = get_jupylint_output(
"python3 ./jupylint/jupylint.py ./jupylint/test_files/stylish.ipynb ./out.py".split(" ")
"python3 ./jupylint_runner.py ./jupylint/test_files/stylish.ipynb ./out.py".split(" ")
)
self.assertFalse(path.isfile("./out.py"))

def test_keep_code_file_set(self):
"""Check that running with the keep flag doesn"t delete the file"""
_ = get_jupylint_output(
"python3 ./jupylint/jupylint.py ./jupylint/test_files/stylish.ipynb ./out.py --keep".split(" ")
"python3 ./jupylint_runner.py ./jupylint/test_files/stylish.ipynb ./out.py --keep".split(" ")
)
self.assertTrue(path.isfile("./out.py"))

@classmethod
def tearDownClass(cls):
"""Clean up, removing any output files left around"""
if path.isfile("./out.py"):
remove("./out.py")


def get_jupylint_output(command):
"""Run a command to get its output, abstracting away error handling"""
Expand Down

0 comments on commit 72dae02

Please sign in to comment.