diff options
Diffstat (limited to 'test/units')
| -rw-r--r-- | test/units/README.md | 7 | ||||
| -rwxr-xr-x | test/units/multi_inventory_test.py | 114 | ||||
| -rwxr-xr-x | test/units/yedit_test.py | 143 | 
3 files changed, 0 insertions, 264 deletions
diff --git a/test/units/README.md b/test/units/README.md deleted file mode 100644 index 78a02c3ea..000000000 --- a/test/units/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Location for python unittests. - -These should be run by sourcing the env-setup: -$ source test/env-setup - -Then navigate to the test/units/ directory. -$ python -m unittest multi_inventory_test diff --git a/test/units/multi_inventory_test.py b/test/units/multi_inventory_test.py deleted file mode 100755 index 168cd82b7..000000000 --- a/test/units/multi_inventory_test.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python2 -''' - Unit tests for MultiInventory -''' - -import unittest -import multi_inventory - -# Removing invalid variable names for tests so that I can -# keep them brief -# pylint: disable=invalid-name -class MultiInventoryTest(unittest.TestCase): -    ''' -     Test class for multiInventory -    ''' - -#    def setUp(self): -#        '''setup method''' -#        pass - -    def test_merge_simple_1(self): -        '''Testing a simple merge of 2 dictionaries''' -        a = {"key1" : 1} -        b = {"key1" : 2} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"key1": [1, 2]}) - -    def test_merge_b_empty(self): -        '''Testing a merge of an emtpy dictionary''' -        a = {"key1" : 1} -        b = {} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"key1": 1}) - -    def test_merge_a_empty(self): -        '''Testing a merge of an emtpy dictionary''' -        b = {"key1" : 1} -        a = {} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"key1": 1}) - -    def test_merge_hash_array(self): -        '''Testing a merge of a dictionary and a dictionary with an array''' -        a = {"key1" : {"hasha": 1}} -        b = {"key1" : [1, 2]} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"key1": [{"hasha": 1}, 1, 2]}) - -    def test_merge_array_hash(self): -        '''Testing a merge of a dictionary with an array and a dictionary with a hash''' -        a = {"key1" : [1, 2]} -        b = {"key1" : {"hasha": 1}} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"key1": [1, 2, {"hasha": 1}]}) - -    def test_merge_keys_1(self): -        '''Testing a merge on a dictionary for keys''' -        a = {"key1" : [1, 2], "key2" : {"hasha": 2}} -        b = {"key2" : {"hashb": 1}} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"key1": [1, 2], "key2": {"hasha": 2, "hashb": 1}}) - -    def test_merge_recursive_1(self): -        '''Testing a recursive merge''' -        a = {"a" : {"b": {"c": 1}}} -        b = {"a" : {"b": {"c": 2}}} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"a": {"b": {"c": [1, 2]}}}) - -    def test_merge_recursive_array_item(self): -        '''Testing a recursive merge for an array''' -        a = {"a" : {"b": {"c": [1]}}} -        b = {"a" : {"b": {"c": 2}}} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"a": {"b": {"c": [1, 2]}}}) - -    def test_merge_recursive_hash_item(self): -        '''Testing a recursive merge for a hash''' -        a = {"a" : {"b": {"c": {"d": 1}}}} -        b = {"a" : {"b": {"c": 2}}} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"a": {"b": {"c": [{"d": 1}, 2]}}}) - -    def test_merge_recursive_array_hash(self): -        '''Testing a recursive merge for an array and a hash''' -        a = {"a" : [{"b": {"c":  1}}]} -        b = {"a" : {"b": {"c": 1}}} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"a": [{"b": {"c": 1}}]}) - -    def test_merge_recursive_hash_array(self): -        '''Testing a recursive merge for an array and a hash''' -        a = {"a" : {"b": {"c": 1}}} -        b = {"a" : [{"b": {"c":  1}}]} -        result = {} -        _ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]] -        self.assertEqual(result, {"a": [{"b": {"c": 1}}]}) - -#    def tearDown(self): -#        '''TearDown method''' -#        pass - -if __name__ == "__main__": -    unittest.main() diff --git a/test/units/yedit_test.py b/test/units/yedit_test.py deleted file mode 100755 index 09a65e888..000000000 --- a/test/units/yedit_test.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python2 -''' - Unit tests for yedit -''' - -import unittest -import os - -# Removing invalid variable names for tests so that I can -# keep them brief -# pylint: disable=invalid-name,no-name-in-module -from yedit import Yedit - -class YeditTest(unittest.TestCase): -    ''' -     Test class for yedit -    ''' -    data = {'a': 'a', -            'b': {'c': {'d': [{'e': 'x'}, 'f', 'g']}}, -           } - -    filename = 'yedit_test.yml' - -    def setUp(self): -        ''' setup method will create a file and set to known configuration ''' -        yed = Yedit(YeditTest.filename) -        yed.yaml_dict = YeditTest.data -        yed.write() - -    def test_load(self): -        ''' Testing a get ''' -        yed = Yedit('yedit_test.yml') -        self.assertEqual(yed.yaml_dict, self.data) - -    def test_write(self): -        ''' Testing a simple write ''' -        yed = Yedit('yedit_test.yml') -        yed.put('key1', 1) -        yed.write() -        self.assertTrue(yed.yaml_dict.has_key('key1')) -        self.assertEqual(yed.yaml_dict['key1'], 1) - -    def test_write_x_y_z(self): -        '''Testing a write of multilayer key''' -        yed = Yedit('yedit_test.yml') -        yed.put('x.y.z', 'modified') -        yed.write() -        yed.load() -        self.assertEqual(yed.get('x.y.z'), 'modified') - -    def test_delete_a(self): -        '''Testing a simple delete ''' -        yed = Yedit('yedit_test.yml') -        yed.delete('a') -        yed.write() -        yed.load() -        self.assertTrue(not yed.yaml_dict.has_key('a')) - -    def test_delete_b_c(self): -        '''Testing delete of layered key ''' -        yed = Yedit('yedit_test.yml') -        yed.delete('b.c') -        yed.write() -        yed.load() -        self.assertTrue(yed.yaml_dict.has_key('b')) -        self.assertFalse(yed.yaml_dict['b'].has_key('c')) - -    def test_create(self): -        '''Testing a create ''' -        os.unlink(YeditTest.filename) -        yed = Yedit('yedit_test.yml') -        yed.create('foo', 'bar') -        yed.write() -        yed.load() -        self.assertTrue(yed.yaml_dict.has_key('foo')) -        self.assertTrue(yed.yaml_dict['foo'] == 'bar') - -    def test_create_content(self): -        '''Testing a create with content ''' -        content = {"foo": "bar"} -        yed = Yedit("yedit_test.yml", content) -        yed.write() -        yed.load() -        self.assertTrue(yed.yaml_dict.has_key('foo')) -        self.assertTrue(yed.yaml_dict['foo'], 'bar') - -    def test_array_insert(self): -        '''Testing a create with content ''' -        yed = Yedit("yedit_test.yml") -        yed.put('b.c.d[0]', 'inject') -        self.assertTrue(yed.get('b.c.d[0]') == 'inject') - -    def test_array_insert_first_index(self): -        '''Testing a create with content ''' -        yed = Yedit("yedit_test.yml") -        yed.put('b.c.d[0]', 'inject') -        self.assertTrue(yed.get('b.c.d[1]') == 'f') - -    def test_array_insert_second_index(self): -        '''Testing a create with content ''' -        yed = Yedit("yedit_test.yml") -        yed.put('b.c.d[0]', 'inject') -        self.assertTrue(yed.get('b.c.d[2]') == 'g') - -    def test_dict_array_dict_access(self): -        '''Testing a create with content''' -        yed = Yedit("yedit_test.yml") -        yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}]) -        self.assertTrue(yed.get('b.c.d[0].[0].x.y') == 'inject') - -    def test_dict_array_dict_replace(self): -        '''Testing multilevel delete''' -        yed = Yedit("yedit_test.yml") -        yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}]) -        yed.put('b.c.d[0].[0].x.y', 'testing') -        self.assertTrue(yed.yaml_dict.has_key('b')) -        self.assertTrue(yed.yaml_dict['b'].has_key('c')) -        self.assertTrue(yed.yaml_dict['b']['c'].has_key('d')) -        self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list)) -        self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list)) -        self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict)) -        self.assertTrue(yed.yaml_dict['b']['c']['d'][0][0]['x'].has_key('y')) -        self.assertTrue(yed.yaml_dict['b']['c']['d'][0][0]['x']['y'], 'testing') - -    def test_dict_array_dict_remove(self): -        '''Testing multilevel delete''' -        yed = Yedit("yedit_test.yml") -        yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}]) -        yed.delete('b.c.d[0].[0].x.y') -        self.assertTrue(yed.yaml_dict.has_key('b')) -        self.assertTrue(yed.yaml_dict['b'].has_key('c')) -        self.assertTrue(yed.yaml_dict['b']['c'].has_key('d')) -        self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list)) -        self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list)) -        self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict)) -        self.assertFalse(yed.yaml_dict['b']['c']['d'][0][0]['x'].has_key('y')) - -    def tearDown(self): -        '''TearDown method''' -        os.unlink(YeditTest.filename) - -if __name__ == "__main__": -    unittest.main()  | 
