You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ja...@apache.org on 2015/02/10 22:55:14 UTC
[5/5] trafficserver-qa git commit: Cleanup of the basic tests that
exist.
Cleanup of the basic tests that exist.
Change assert() to assertEqual
Project: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/commit/1eb2e71e
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/tree/1eb2e71e
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/diff/1eb2e71e
Branch: refs/heads/master
Commit: 1eb2e71eb6f7810cf1b68859b4750faeba7b1ece
Parents: 8058188
Author: Thomas Jackson <ja...@gmail.com>
Authored: Fri Feb 6 17:16:42 2015 -0800
Committer: Thomas Jackson <ja...@gmail.com>
Committed: Tue Feb 10 13:54:08 2015 -0800
----------------------------------------------------------------------
tests/example_test.py | 14 -------------
tests/hello_world_test.py | 4 +++-
tests/helpers.py | 39 ++++++++++++++++++++++++++++++------
tests/utils/buildcache_test.py | 10 +++++-----
tests/utils/utils_test.py | 40 +++++++++++++++++++------------------
5 files changed, 62 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/1eb2e71e/tests/example_test.py
----------------------------------------------------------------------
diff --git a/tests/example_test.py b/tests/example_test.py
deleted file mode 100644
index d91cf19..0000000
--- a/tests/example_test.py
+++ /dev/null
@@ -1,14 +0,0 @@
-'''
-This is a terrible example of how you would write some tests for tsqa
-'''
-
-import tsqa.utils
-unittest = tsqa.utils.import_unittest()
-
-def test_example():
- assert True == True
-
-class TestExample(unittest.TestCase):
- def test_example(self):
- assert True == True
-
http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/1eb2e71e/tests/hello_world_test.py
----------------------------------------------------------------------
diff --git a/tests/hello_world_test.py b/tests/hello_world_test.py
index 302e4b2..0c13651 100644
--- a/tests/hello_world_test.py
+++ b/tests/hello_world_test.py
@@ -8,6 +8,8 @@ This should:
- send a request through
- check that it worked
'''
+import helpers
+
import tsqa.utils
unittest = tsqa.utils.import_unittest()
import tsqa.test_cases
@@ -16,7 +18,7 @@ import tsqa.environment
import requests
import time
-class TestEnvironmentCase(tsqa.test_cases.EnvironmentCase):
+class TestEnvironmentCase(helpers.EnvironmentCase):
def test_base(self):
assert isinstance(self.environment, tsqa.environment.Environment)
http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/1eb2e71e/tests/helpers.py
----------------------------------------------------------------------
diff --git a/tests/helpers.py b/tests/helpers.py
index df5a18a..e01b2e1 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -1,22 +1,49 @@
import subprocess
import os
+import os.path
+import tempfile
-from tsqa.utils import run_sync_command
+import tsqa.test_cases
-TMP_DIR = '/tmp/tsqa/'
+import tsqa.utils
+
+TMP_DIR = os.path.join(tempfile.gettempdir(), 'tsqa')
+unittest = tsqa.utils.import_unittest()
def source_dir():
'''
return the directory where source code is checked out
'''
+ path = os.path.join(TMP_DIR, 'trafficserver')
# if we don't have it, clone it
- if not os.path.exists(TMP_DIR):
- os.makedirs(TMP_DIR)
- run_sync_command(['git', 'clone', 'https://github.com/apache/trafficserver.git'],
+ if not os.path.exists(path):
+ tsqa.utils.run_sync_command(['git', 'clone', 'https://github.com/apache/trafficserver.git'],
cwd=TMP_DIR,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
- return TMP_DIR
+ return os.path.join(TMP_DIR, 'trafficserver')
+
+class EnvironmentCase(tsqa.test_cases.EnvironmentCase):
+ '''
+ This class will get an environment (which is unique) but won't start it
+ '''
+ @classmethod
+ def getEnv(cls):
+ '''
+ This function is responsible for returning an environment
+ '''
+ SOURCE_DIR = os.path.realpath(os.path.join(__file__, '..', '..', '..', '..'))
+ TMP_DIR = os.path.join(tempfile.gettempdir(), 'tsqa')
+ ef = tsqa.environment.EnvironmentFactory(source_dir(),
+ os.path.join(TMP_DIR, 'base_envs'),
+ default_configure={'enable-example-plugins': None,
+ 'enable-test-tools': None,
+ 'enable-example-plugins': None,
+ },
+ )
+ # TODO: figure out a way to determine why the build didn't fail and
+ # not skip all build failures?
+ return ef.get_environment(cls.environment_factory['configure'], cls.environment_factory['env'])
http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/1eb2e71e/tests/utils/buildcache_test.py
----------------------------------------------------------------------
diff --git a/tests/utils/buildcache_test.py b/tests/utils/buildcache_test.py
index 818fa65..ac75fcd 100644
--- a/tests/utils/buildcache_test.py
+++ b/tests/utils/buildcache_test.py
@@ -24,11 +24,11 @@ class TestBuildCache(unittest.TestCase):
def test_base(self):
cache = tsqa.utils.BuildCache(self.tmp_dir)
- assert cache == {}
+ self.assertEqual(cache, {})
cache.save_cache()
- assert os.path.exists(self.cache_map_file)
+ self.assertTrue(os.path.exists(self.cache_map_file))
cache.load_cache()
- assert cache == {}
+ self.assertEqual(cache, {})
def test_load_cache(self):
# make sure that a bad cache file gets emptied
@@ -36,7 +36,7 @@ class TestBuildCache(unittest.TestCase):
fh.write(json.dumps({'foo': {}}))
cache = tsqa.utils.BuildCache(self.tmp_dir)
- assert cache == {}
+ self.assertEqual(cache, {})
def test_save_cache(self):
cache = tsqa.utils.BuildCache(self.tmp_dir)
@@ -44,7 +44,7 @@ class TestBuildCache(unittest.TestCase):
with open(self.cache_map_file) as fh:
json_cache = json.load(fh)
- assert json_cache == {'foo': {'a': 'somepath'}}
+ self.assertEqual(json_cache, {'foo': {'a': 'somepath'}})
http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/1eb2e71e/tests/utils/utils_test.py
----------------------------------------------------------------------
diff --git a/tests/utils/utils_test.py b/tests/utils/utils_test.py
index 91547bd..324adfe 100644
--- a/tests/utils/utils_test.py
+++ b/tests/utils/utils_test.py
@@ -3,26 +3,28 @@ Test the utils
'''
import tsqa.utils
+unittest = tsqa.utils.import_unittest()
-def test_merge_dicts():
- '''
- These dicts should be merged in order, meaning latter ones will override
- earlier ones.
- '''
- assert tsqa.utils.merge_dicts({'a': 1}, {'a': 2}) == {'a': 2}
- assert tsqa.utils.merge_dicts({'a': 1}, {'b': 2}) == {'a': 1, 'b': 2}
+class TestUtils(unittest.TestCase):
+ def test_merge_dicts(self):
+ '''
+ These dicts should be merged in order, meaning latter ones will override
+ earlier ones.
+ '''
+ self.assertEqual(tsqa.utils.merge_dicts({'a': 1}, {'a': 2}), {'a': 2})
+ self.assertEqual(tsqa.utils.merge_dicts({'a': 1}, {'b': 2}), {'a': 1, 'b': 2})
-def test_configure_list():
- '''
- Test that we can convert a dict to a list of configure strings
- '''
- assert tsqa.utils.configure_list({'a': 'b', 'c': None}) == ['--a=b', '--c']
+ def test_configure_list(self):
+ '''
+ Test that we can convert a dict to a list of configure strings
+ '''
+ self.assertEqual(tsqa.utils.configure_list({'a': 'b', 'c': None}), ['--a=b', '--c'])
-def test_configure_string_to_dict():
- '''
- Can we reverse it?
- '''
- assert tsqa.utils.configure_string_to_dict('--a') == {'a': None}
- assert tsqa.utils.configure_string_to_dict('--a=b') == {'a': 'b'}
- assert tsqa.utils.configure_string_to_dict('--a=b --c') == {'a': 'b', 'c': None}
+ def test_configure_string_to_dict(self):
+ '''
+ Can we reverse it?
+ '''
+ self.assertEqual(tsqa.utils.configure_string_to_dict('--a'), {'a': None})
+ self.assertEqual(tsqa.utils.configure_string_to_dict('--a=b'), {'a': 'b'})
+ self.assertEqual(tsqa.utils.configure_string_to_dict('--a=b --c'), {'a': 'b', 'c': None})