Skip to content

Commit

Permalink
Other: start writing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Dec 19, 2016
1 parent e09516c commit d6dd280
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
@@ -0,0 +1,6 @@
[run]
omit =
*/common/vendor/*
*/tests/*
common/vendor/*
tests/*
44 changes: 44 additions & 0 deletions .travis.yml
@@ -0,0 +1,44 @@
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
echo `python --version`;
pip install python-coveralls;
fi
- coveralls

notifications:
email: false
14 changes: 14 additions & 0 deletions appveyor.yml
@@ -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
Empty file added tests/test_git/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/test_git/common.py
@@ -0,0 +1,10 @@
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)
47 changes: 47 additions & 0 deletions tests/test_git/test_git_init.py
@@ -0,0 +1,47 @@
import sublime
import os
import subprocess
from unittesting.helpers import TempDirectoryTestCase
from .common import AssertionsMixin
from GitSavvy.core import git_command


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


class TestInitialization(TempDirectoryTestCase, AssertionsMixin, git_command.GitCommand):
"""
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
"""

def test_01_init(self):
self.assertEqual(
tidy_path(self._temp_dir),
tidy_path(sublime.active_window().folders()[0]))
subprocess.check_call(["git", "init"], cwd=self._temp_dir)
self.assertEqual(
tidy_path(self._temp_dir),
tidy_path(self.window.folders()[0]))

def test_02_add_first_file(self):
readme = os.path.join(self.repo_path, "README.md")
f = open(readme, "w")
f.write("README")
f.close()
self.git("add", "README.md")
self.git("commit", "-m", "Init")

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

def test_04_untrack_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])
Empty file added tests/test_ui/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions unittesting.json
@@ -0,0 +1,4 @@
{
"deferred": true,
"capture_console": true
}

0 comments on commit d6dd280

Please sign in to comment.