Skip to content

Commit

Permalink
Merge branch 'master' into encoding_inlinediff
Browse files Browse the repository at this point in the history
  • Loading branch information
stoivo committed Feb 28, 2017
2 parents 83d7cdf + c80cdee commit aafc407
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
env:
global:
- PACKAGE="GitSavvy"
- SUBLIME_TEXT_VERSION="3"
- UNITTESTING_TAG="master"

matrix:
include:
- os: linux
language: python
python: 3.3
- os: osx
language: generic

before_install:
- curl -OL https://raw.githubusercontent.com/randy3k/UnitTesting/master/sbin/travis.sh
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
export DISPLAY=:99.0;
sh -e /etc/init.d/xvfb start;
fi
- git config --global user.email gitsavvy@gitsavvy.com
- git config --global user.name GitSavvy

install:
- sh travis.sh bootstrap
- sh travis.sh install_package_control

script:
- sh travis.sh run_tests --coverage

after_success:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update;
brew install python3;
pip3 install python-coveralls;
fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
pip install python-coveralls;
fi
- coveralls

notifications:
email: false
5 changes: 5 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ If you're interested in tackling a bug, please say so and I can assign it to you
# Documentation

If you make changes, please remember to update the user documentation to reflect the new behavior.


## Package Testing

Check the implementation details of the [tests](docs/testing.md).
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# GitSavvy

[![Build Status](https://travis-ci.org/divmain/GitSavvy.svg?branch=master)](https://travis-ci.org/divmain/GitSavvy)
[![AppVeyor branch](https://img.shields.io/appveyor/ci/divmain/GitSavvy/master.svg)](https://ci.appveyor.com/project/divmain/GitSavvy)
[![Coverage Status](https://coveralls.io/repos/github/divmain/GitSavvy/badge.svg)](https://coveralls.io/github/divmain/GitSavvy)
[![Codacy Badge](https://www.codacy.com/project/badge/3c214fa790b249f79f5275dbfa6499ca)](https://www.codacy.com/app/dale/GitSavvy)
![License](https://camo.githubusercontent.com/890acbdcb87868b382af9a4b1fac507b9659d9bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/divmain/GitSavvy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
14 changes: 14 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
environment:
PACKAGE: "GitSavvy"
SUBLIME_TEXT_VERSION : "3"
UNITTESTING_TAG : "master"

install:
- ps: appveyor DownloadFile "https://raw.githubusercontent.com/randy3k/UnitTesting/master/sbin/appveyor.ps1"
- ps: .\appveyor.ps1 "bootstrap" -verbose
- ps: .\appveyor.ps1 "install_package_control" -verbose

build: off

test_script:
- ps: .\appveyor.ps1 "run_tests" -verbose
32 changes: 32 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Package Testing

We try to cover the most crucial functionality with unit tests using
[UnitTesting](https://github.com/randy3k/UnitTesting). To run the tests
locally, you should install UnitTesting via Package Control.

## Run the test specs locally

First you need to [clone](https://github.com/divmain/GitSavvy#less-simple) GitSavvy repo from source.
Open the directory `GitSavvy` and simply run the command `UnitTesting: Test Current Project`

## Some details about DeferrableTestCase

[DeferrableTestCase][1] is used to write the test cases. They are executed by
the [DeferringTextTestRunner][2] and the runner expects not only regular test
functions, but also generators. If the test function is a generator, it does
the following

- if the yielded object is a callable, the runner will evaluate the
[callable][3] and check its returned value. If the result is `True`, the
runner continues the generator, if not, the runner will wait until the
condition is met.

- If the yielded object is an integer, say `x`, then it will [continue][4] the
generator after `x` ms.

- Otherwise, the `yield` statement will always wait for 10 ms.

[1]: https://github.com/randy3k/UnitTesting/blob/dc810ee334bb031710b859478faaf50293880995/unittesting/core/st3/runner.py#L49
[2]: https://github.com/randy3k/UnitTesting/blob/dc810ee334bb031710b859478faaf50293880995/unittesting/core/st3/runner.py#L7
[3]: https://github.com/randy3k/UnitTesting/blob/dc810ee334bb031710b859478faaf50293880995/unittesting/core/st3/runner.py#L49
[4]: https://github.com/randy3k/UnitTesting/blob/dc810ee334bb031710b859478faaf50293880995/unittesting/core/st3/runner.py#L57
Empty file added tests/test_git/__init__.py
Empty file.
49 changes: 49 additions & 0 deletions tests/test_git/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sublime
import subprocess
import os
from unittesting.helpers import TempDirectoryTestCase


def tidy_path(path):
return os.path.realpath(os.path.normcase(path))


class AssertionsMixin:

def assert_git_status(self, status):
"""
Assertion of the current git status. `status` should be a list of 4 intergers:
The lengths of the staged, unstaged, untracked and conflicted entries.
"""
self.assertEqual(
[len(x) for x in self.sort_status_entries(self.get_status())],
status)


class GitRepoTestCase(TempDirectoryTestCase, AssertionsMixin):
"""
TempDirectoryTestCase is a subclass of DeferrableTestCase which creates and opens a temp
directory before running the test case and close the window when the test case finishes running.
https://github.com/randy3k/UnitTesting/blob/master/unittesting/helpers.py
"""
# add readme file as the initial commit
initialize = True

@classmethod
def setUpClass(cls):
# since TempDirectoryTestCase.setUpClass is a generator
yield from super(GitRepoTestCase, cls).setUpClass()
assert tidy_path(cls._temp_dir) == tidy_path(sublime.active_window().folders()[0])
assert tidy_path(cls._temp_dir) == tidy_path(cls.window.folders()[0])
subprocess.check_call(["git", "init"], cwd=cls._temp_dir)
if cls.initialize:
cls.add_readme()

@classmethod
def add_readme(cls):
readme = os.path.join(cls._temp_dir, "README.md")
f = open(readme, "w")
f.write("README")
f.close()
subprocess.check_call(["git", "add", "README.md"], cwd=cls._temp_dir)
subprocess.check_call(["git", "commit", "-m", "Add README.md"], cwd=cls._temp_dir)
21 changes: 21 additions & 0 deletions tests/test_git/test_git_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from .common import GitRepoTestCase
from GitSavvy.core import git_command


class TestInitialization(GitRepoTestCase, git_command.GitCommand):

def test_is_master(self):
branch = self.get_current_branch_name()
self.assertEqual(branch, "master")


class TestStageFile(GitRepoTestCase, git_command.GitCommand):

def test_stage_file(self):
foo = os.path.join(self.repo_path, "foo")
with open(foo, "w") as f:
f.write("foo")
self.assert_git_status([0, 0, 1, 0])
self.stage_file(foo)
self.assert_git_status([1, 0, 0, 0])
4 changes: 4 additions & 0 deletions unittesting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"deferred": true,
"capture_console": true
}

0 comments on commit aafc407

Please sign in to comment.