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

Change the way tests are parsed in scent.py #32

Open
ignat980 opened this issue Feb 22, 2016 · 0 comments
Open

Change the way tests are parsed in scent.py #32

ignat980 opened this issue Feb 22, 2016 · 0 comments

Comments

@ignat980
Copy link

[Feature request]
I think that you should be able to use regex to match which files are watched for changes, and which files get run.

This is basically guard but for python. The syntax for a guardfile is so clean, you just type

guard :<rspec/minitest/testing framework> [, options ] do
    watch(<file regex or file name to watch>) [{|m| <file regex or filename or directory to run>}]
end

Where watch is a function that takes a regex search and an optional function that takes the matching string and the regex groups for what files to run.
We could call this function sniff (because sniffer)

My current scent.py file is

from sniffer.api import *
from subprocess import call
from datetime import datetime
import os 

watch_paths = ['.', 'test/']

# Define validator for running a specific function before all the tests
@select_runnable('first')
@file_validator
def python_files(filename):
    return filename.endswith('.py') and not os.path.basename(filename).startswith('.')


@select_runnable('linked_list_test')
@file_validator
def linked_list_file(filename):
    return filename.endswith('linked_list.py')


@select_runnable('hash_table_test')
@file_validator
def hash_table_file(filename):
    return filename.endswith('hash_table.py')


@runnable
def linked_list_test(*args):
    print("===Linked List Tests===")
    command = "nosetests test/test_linked_list.py -v")
    return call(command, shell=True) == 0


@runnable
def hash_table_test(*args):
    print("===Hash Table Tests===")
    command = "nosetests test/test_hash_table.py -v")
    return call(command, shell=True) == 0


@runnable
def first(*args):
    print(str(datetime.now()))
    return True

which is a lot just to say to run specific files based on name. There is a lot of repetition.

I believe the api could be changed to work more like guard, the scent.py file could look like (to do the same thing as above)

from sniffer.api import *
from datetime import datetime
import os

## The default should be to track all subfolders
## Uncomment and sniffer will watch only specific directories
# watch_directories = ["."x, "test/"]

@sniffer_setup
def func_name(sniffer):
    # nosetest arguments
    sniffer.args = ["-v"]
    # run this optional function every time before a test
    sniffer.before = print_time
    # Watch for and execute any file in test subfolder that are in the form of "test_name.py"
    sniffer.sniff(r"^test/test_(.*)\.py$")
    # Watch for any file in root directory and execute the relevant test file
    sniffer.sniff(r"(.*)\.py", tests_based_on_groups)

def tests_based_on_groups(file_string, groups)
    return "test/test_" + groups[0] + ".py"

def print_time():
    print(str(datetime.now()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant