Skip to content

Commit

Permalink
Feature: Added function to run a single nose method that is outside o…
Browse files Browse the repository at this point in the history
…f a class
  • Loading branch information
JarrodCTaylor committed Sep 26, 2014
1 parent a883269 commit 043e09e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
36 changes: 17 additions & 19 deletions README.md
Expand Up @@ -39,18 +39,17 @@ pip installed in order for the plugin to function properly.

## Usage

The plugin provides eight commands:

```
DjangoTestApp
DjangoTestFile
DjangoTestClass
DjangoTestMethod
NosetestFile
NosetestClass
NosetestMethod
RerunLastTests
```
The plugin provides nine commands:

- `DjangoTestApp`: Run all tests for the current app
- `DjangoTestFile`: Run all tests in the current file
- `DjangoTestClass`: Run all tests in the current class
- `DjangoTestMethod`: Run test for the current method
- `NosetestFile`: Run all tests for the current file
- `NosetestClass`: Run all tests in the current class
- `NosetestMethod`: Run the current test method (inside of a class)
- `NosetestBaseMethod`: Run the current test method (outside of a class)
- `RerunLastTests`: Rerun the last tests

All arguments can be tab-completed. Ensure that your cursor is within a
file, class or method as appropriate for the command being called.
Expand All @@ -67,6 +66,7 @@ your vimrc:
nnoremap<Leader>nf :NosetestFile<CR>
nnoremap<Leader>nc :NosetestClass<CR>
nnoremap<Leader>nm :NosetestMethod<CR>
nnoremap<Leader>nb :NosetestBaseMethod<CR>
nnoremap<Leader>rr :RerunLastTests<CR>
```

Expand Down Expand Up @@ -114,16 +114,14 @@ tests for.
#### Optional fields

Optional fields that can be set in the vim-django config file are as follows:
- `environment`: If you have modifyed your manage.py file to accept an environment argument
- `environment`: If you have modified your manage.py file to accept an environment argument
then you may use the environment flag to specify which one to run tests for.
Example `"environment": "dev"` If you haven't modifyed your manage.py file
Example `"environment": "dev"` If you haven't modified your manage.py file
then you don't need to use this.

- `failfast`: Enable the django-nose builtin failfast option by specifying
failfast to be true. Example `"failfast": true`
- `flags`: An array of flags that you would like passed to the test runner
See example config file below for usage.

- `nocapture`: Enable the django-nose builtin nocapture option by specifiying
nocapture to be true. Example `"nocapture": true`

#### vim-django config file example

Expand All @@ -134,7 +132,7 @@ the fail fast option.
```
{"app_name": "app1, app2",
"environment": "OptionalNameOfEnv",
"failfast": true}
"flags": ["failfast"]}
```
*NOTE* be sure to use double quotes in the config file as it is parsed as json

Expand Down
37 changes: 18 additions & 19 deletions doc/vim-python-test-runner.txt
Expand Up @@ -60,16 +60,17 @@ pip installed in order for the plugin to function properly.
===============================================================================
4. Usage *test-runner-usage*

The plugin provides eight commands:

DjangoTestApp
DjangoTestFile
DjangoTestClass
DjangoTestMethod
NosetestFile
NosetestClass
NosetestMethod
RerunLastTests
The plugin provides nine commands:

- `DjangoTestApp`: Run all tests for the current app
- `DjangoTestFile`: Run all tests in the current file
- `DjangoTestClass`: Run all tests in the current class
- `DjangoTestMethod`: Run test for the current method
- `NosetestFile`: Run all tests for the current file
- `NosetestClass`: Run all tests in the current class
- `NosetestMethod`: Run the current test method (inside of a class)
- `NosetestBaseMethod`: Run the current test method (outside of a class)
- `RerunLastTests`: Rerun the last tests

All arguments can be tab-completed. Ensure that your cursor is within a
file, class or method as appropriate for the command being called.
Expand All @@ -85,6 +86,7 @@ your vimrc:
nnoremap<Leader>nf :NosetestFile<CR>
nnoremap<Leader>nc :NosetestClass<CR>
nnoremap<Leader>nm :NosetestMethod<CR>
nnoremap<Leader>nb :NosetestBaseMethod<CR>
nnoremap<Leader>rr :RerunLastTests<CR>

Your tests results will be available in the quickfix window after they finish
Expand Down Expand Up @@ -125,15 +127,12 @@ tests for.

Optional fields that can be set in the vim-django config file are as follows:
- `environment`: If you have modifyed your manage.py file to accept an environment argument
then you may use the environment flag to specify which one to run tests for.
Example `"environment": "dev"` If you haven't modifyed your manage.py file
then you don't need to use this.

- `failfast`: Enable the django-nose builtin failfast option by specifying
failfast to be true. Example `"failfast": true`
then you may use the environment flag to specify which one to run tests for.
Example `"environment": "dev"` If you haven't modifyed your manage.py file
then you don't need to use this.

- `nocapture`: Enable the django-nose builtin nocapture option by specifiying
nocapture to be true. Example `"nocapture": true`
- `flags`: An array of flags that you would like passed to the test runner
See example config file below for usage.

5.1.3 *vim-django-config-file-example*

Expand All @@ -144,7 +143,7 @@ the fail fast option.
```
{"app_name": "app1, app2",
"environment": "OptionalNameOfEnv",
"failfast": true}
"flags": ["failfast"]}
```
*NOTE* be sure to use double quotes in the config file as it is parsed as json

Expand Down
6 changes: 6 additions & 0 deletions ftplugin/python/tests/classless_dummy_file.py
@@ -0,0 +1,6 @@
def dummy_base_method1():
print('This is a testI')
print('This is a testII')
print('This is a testIII')
print('This is a testIV')
print('This is a testV')
11 changes: 9 additions & 2 deletions ftplugin/python/tests/run_nosetests_in_vim_tests.py
Expand Up @@ -46,8 +46,15 @@ def test_create_command_to_run_current_method_with_nosetests_writes_command_to_c
last_command = sut.get_command_to_rerun_last_tests()
self.assertEqual(command_to_run, last_command)

def build_buffer_helper(self):
with open("dummy_test_file.py", "r") as f:
def test_create_command_to_run_current_method_with_nosetests_when_not_in_a_class(self):
path_to_current_file = "/tmp/project/tests/aTestFile.py"
current_line = 5
current_buffer = self.build_buffer_helper("classless_dummy_file.py")
command_to_run = sut.get_command_to_run_current_base_method_with_nosetests(path_to_current_file, current_line, current_buffer)
self.assertEqual(":!nosetests /tmp/project/tests/aTestFile.py:dummy_base_method1", command_to_run)

def build_buffer_helper(self, dummy_file="dummy_test_file.py"):
with open(dummy_file, "r") as f:
current_buffer = []
for line in f.readlines():
current_buffer.append(line)
Expand Down
8 changes: 8 additions & 0 deletions ftplugin/python/vim_python_test_runner.py
Expand Up @@ -70,6 +70,14 @@ def get_command_to_run_current_method_with_nosetests(path_to_current_file, curre
return command


def get_command_to_run_current_base_method_with_nosetests(path_to_current_file, current_line, current_buffer):
run_file = get_command_to_run_current_file_with_nosetests(path_to_current_file)
current_method = get_current_method_and_class(current_line, current_buffer)[1]
command = run_file + ":" + current_method
write_test_command_to_cache_file(command)
return command


def get_command_to_rerun_last_tests():
with open("/tmp/vim_python_test_runner_cache", "r") as f:
return f.read()
Expand Down
2 changes: 2 additions & 0 deletions ftplugin/python/vim_python_test_runner.vim
Expand Up @@ -28,6 +28,7 @@ def get_proper_command(desired_command, current_directory):
"nose_file": lambda: get_command_to_run_current_file_with_nosetests(vim.current.buffer.name),
"nose_class": lambda: get_command_to_run_current_class_with_nosetests(vim.current.buffer.name, current_line_index, vim.current.buffer),
"nose_method": lambda: get_command_to_run_current_method_with_nosetests(vim.current.buffer.name, current_line_index, vim.current.buffer),
"nose_base_method": lambda: get_command_to_run_current_base_method_with_nosetests(vim.current.buffer.name, current_line_index, vim.current.buffer),
"rerun": lambda: get_command_to_rerun_last_tests()
}
return FUNCTIONS[desired_command]()
Expand Down Expand Up @@ -61,4 +62,5 @@ command! DjangoTestMethod call RunDesiredTests("django_method")
command! NosetestFile call RunDesiredTests("nose_file")
command! NosetestClass call RunDesiredTests("nose_class")
command! NosetestMethod call RunDesiredTests("nose_method")
command! NosetestBaseMethod call RunDesiredTests("nose_base_method")
command! RerunLastTests call RunDesiredTests("rerun")

0 comments on commit 043e09e

Please sign in to comment.