Skip to content

Commit

Permalink
resource lookup in unit tests is now relative
Browse files Browse the repository at this point in the history
  • Loading branch information
dexterous committed Sep 21, 2011
1 parent d5845ab commit ffa8812
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 57 deletions.
9 changes: 7 additions & 2 deletions other_tests/tests_freshen_nose_plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import unittest

import os
import sys

from freshen.noseplugin import FreshenNosePlugin
from optparse import OptionParser

class TestFreshenTestCaseName(unittest.TestCase):

def __init__(self, method_name='runTest'):
unittest.TestCase.__init__(self, method_name)
self.cur_dir = os.path.dirname(os.path.abspath(__file__))

def _make_plugin(self):
plugin = FreshenNosePlugin()
parser = OptionParser()
Expand All @@ -21,14 +26,14 @@ def _make_plugin(self):

def test_should_use_feature_name_as_class_name_when_subclassing_FreshenTestCase(self):
plugin = self._make_plugin()
test_generator = plugin.loadTestsFromFile('./resources/valid_no_tags_no_use_only.feature')
test_generator = plugin.loadTestsFromFile(self.cur_dir + '/resources/valid_no_tags_no_use_only.feature')
test_instance = test_generator.next()

self.assertEquals(test_instance.__class__.__name__, 'Independence of the counter.')

def test_should_use_scenario_name_as_method_name_when_subclassing_FreshenTestCase(self):
plugin = self._make_plugin()
test_generator = plugin.loadTestsFromFile('./resources/valid_no_tags_no_use_only.feature')
test_generator = plugin.loadTestsFromFile(self.cur_dir + '/resources/valid_no_tags_no_use_only.feature')
test_instance = test_generator.next()

self.assertNotEqual(getattr(test_instance, 'Print counter', None), None)
115 changes: 60 additions & 55 deletions other_tests/tests_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,130 @@
from freshen.core import load_language
from freshen.parser import parse_file

import os

class TestParseValidFeature(unittest.TestCase):
"""
Tests for the parsing of a valid feature.
"""

def setUp(self):
self.language = load_language('en')
self.cur_dir = os.path.dirname(os.path.abspath(__file__))



def test_should_parse_feature_file_without_tags_and_without_use_only(self):
feature = parse_file('resources/valid_no_tags_no_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_no_use_only.feature', self.language)
self.assertEquals(feature.name, 'Independence of the counter.')


def test_should_parse_feature_file_with_tags_and_without_use_only(self):
feature = parse_file('resources/valid_with_tags_no_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_no_use_only.feature', self.language)
self.assertEquals(feature.tags[0], 'one')


def test_should_parse_feature_file_without_tags_and_with_use_only(self):
feature = parse_file('resources/valid_no_tags_with_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_with_use_only.feature', self.language)
self.assertEquals(feature.use_step_defs[0], 'independent_one')


def test_should_parse_feature_file_without_tags_and_with_multiple_use_only(self):
feature = parse_file('resources/valid_no_tags_with_multiple_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_with_multiple_use_only.feature', self.language)
self.assertEquals(feature.use_step_defs[0], 'independent_one')
self.assertEquals(feature.use_step_defs[1], 'te st')


def test_should_parse_feature_file_with_tags_and_with_use_only(self):
feature = parse_file('resources/valid_with_tags_with_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_with_use_only.feature', self.language)
self.assertEquals(feature.tags[0], 'one')
self.assertEquals(feature.use_step_defs[0], 'independent_one')


def test_should_parse_feature_file_with_tags_and_with_multiple_use_only(self):
feature = parse_file('resources/valid_with_tags_with_multiple_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_with_multiple_use_only.feature', self.language)
self.assertEquals(feature.tags[0], 'one')
self.assertEquals(feature.use_step_defs[0], 'independent_one')
self.assertEquals(feature.use_step_defs[1], 'te st')


def test_should_parse_feature_file_with_unicode_use_only(self):
feature = parse_file('resources/valid_with_tags_with_unicode_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_with_unicode_use_only.feature', self.language)
self.assertEquals(feature.tags[0], 'one')
self.assertEquals(feature.use_step_defs[0], 'unicodeèédç')


def test_should_parse_feature_file_with_full_unix_path_use_only(self):
feature = parse_file('resources/valid_with_tags_with_full_unix_path_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_with_full_unix_path_use_only.feature', self.language)
self.assertEquals(feature.tags[0], 'one')
self.assertEquals(feature.use_step_defs[0], '/home/user/independent_one.py')


def test_should_parse_feature_file_with_full_windows_path_use_only(self):
feature = parse_file('resources/valid_with_tags_with_full_windows_path_use_only.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_with_full_windows_path_use_only.feature', self.language)
self.assertEquals(feature.tags[0], 'one')
self.assertEquals(feature.use_step_defs[0], 'C:\\Documents and Settings\\user\\Desktop\\independent_one.py')


def test_should_parse_feature_file_with_use_only_short_form(self):
feature = parse_file('resources/valid_no_tags_with_use_only_short_form.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_with_use_only_short_form.feature', self.language)
self.assertEquals(feature.use_step_defs[0], 'independent_one')


def test_should_parse_feature_file_with_background_and_no_tags(self):
feature = parse_file('resources/Befriend_without_tags.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/Befriend_without_tags.feature', self.language)
self.assertTrue(feature.has_background())
self.assertEquals(len(feature.background.steps), 2)
self.assertEquals(len(feature.scenarios), 2)


def test_should_parse_feature_file_with_background_and_tags(self):
feature = parse_file('resources/Befriend_with_tags.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/Befriend_with_tags.feature', self.language)
self.assertTrue(feature.has_background())
self.assertEquals(len(feature.background.steps), 2)
self.assertEquals(len(feature.scenarios), 2)
self.assertEquals(len(feature.scenarios[0].tags), 1)


def test_should_parse_feature_file_with_background_and_title_and_tags(self):
feature = parse_file('resources/Befriend_with_tags_and_background_title.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/Befriend_with_tags_and_background_title.feature', self.language)
self.assertTrue(feature.has_background())
self.assertEquals(len(feature.background.steps), 2)
self.assertEquals(len(feature.scenarios), 2)
self.assertEquals(len(feature.scenarios[0].tags), 1)


class TestParseValidFeatureInFrench(unittest.TestCase):
"""
Tests for the parsing of a valid feature in French.
"""

def setUp(self):
self.language = load_language('fr')
self.cur_dir = os.path.dirname(os.path.abspath(__file__))



def test_should_parse_feature_file_without_tags_and_without_use_only(self):
feature = parse_file('resources/valid_no_tags_no_use_only_fr.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_no_use_only_fr.feature', self.language)
self.assertEquals(feature.name, "L'indépendance des compteurs.")


def test_should_parse_feature_file_with_tags_and_without_use_only(self):
feature = parse_file('resources/valid_with_tags_no_use_only_fr.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_no_use_only_fr.feature', self.language)
self.assertEquals(feature.tags[0], 'un')


def test_should_parse_feature_file_without_tags_and_with_use_only(self):
feature = parse_file('resources/valid_no_tags_with_use_only_fr.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_with_use_only_fr.feature', self.language)
self.assertEquals(feature.use_step_defs[0], 'independent_one')


def test_should_parse_feature_file_with_use_only_short_form_fr(self):
feature = parse_file('resources/valid_no_tags_with_use_only_short_form_fr.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_no_tags_with_use_only_short_form_fr.feature', self.language)
self.assertEquals(feature.use_step_defs[0], 'independent_one')


def test_should_parse_feature_file_with_background_and_no_tags_fr(self):
feature = parse_file('resources/Befriend_without_tags_fr.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/Befriend_without_tags_fr.feature', self.language)
self.assertTrue(feature.has_background())
self.assertEquals(len(feature.background.steps), 2)
self.assertEquals(len(feature.scenarios), 2)
Expand All @@ -135,21 +139,22 @@ def test_should_parse_feature_file_with_background_and_no_tags_fr(self):
class TestParseValidFeatureInBulgarian(unittest.TestCase):
"""
Tests for the parsing of a valid feature in Bulgarian.
@note: This test is used to ensure that if a keyword is not translated
in a given language, then the missing keyword can be spelled in English.
"""

def setUp(self):
self.language = load_language('bg')
self.cur_dir = os.path.dirname(os.path.abspath(__file__))



def test_should_parse_feature_file_with_tags_and_with_multiple_use_only(self):
feature = parse_file('resources/valid_with_tags_with_multiple_use_only_bg.feature', self.language)
feature = parse_file(self.cur_dir + '/resources/valid_with_tags_with_multiple_use_only_bg.feature', self.language)
self.assertEquals(feature.tags[0], 'one')
self.assertEquals(feature.use_step_defs[0], 'independent_one')
self.assertEquals(feature.use_step_defs[1], 'te st')


if __name__ == "__main__":
unittest.main()

0 comments on commit ffa8812

Please sign in to comment.