test_repository.py 2.4 KB
Newer Older
1
2
import unittest
import pkg_resources
3
import os.path
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from psot import config

class TestExampleRepositoryIsLoadedCorrectly(unittest.TestCase):
  def setUp(self):
    repo_path = pkg_resources.resource_filename('tests', 'data/example_repo/')
    self.repository = config.Repository(repo_path)
    self.config = self.repository.load_config()

  def test_that_profile_exists(self):
    # check that a profile with the name 'test' exists in the list of profiles
    for profile in self.config['profiles']:
      if 'test' == profile['name']:
        return
    self.fail('Profile test not found')

  def test_that_module_exits(self):
    # check that a module with the name 'example' exists in the list of modules
    self.assertTrue('example' in self.config['modules'], 'Module example not found')

23
24
25
26
27
28
29
30
  def test_that_run_script_is_resolved_correctly(self):
    # all paths to scripts should be stored as absolute paths in the configuration. This tests checks if the scripts are reachable via the path specified
    script_path = self.config['modules']['example']['analysis']['script']
    self.assertTrue(os.path.isfile(script_path), "Script is not a file " + script_path)

  def test_that_convert_script_is_resolved_correctly(self):
    script_path = self.config['modules']['example']['converter']['script']
    self.assertTrue(os.path.isfile(script_path), "Script is not a file " + script_path)
31
32

  def test_that_config_exists(self):
33
    self.assertTrue('tools' in self.config, 'config.yml not loaded')
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


class TestMergingRepositoriesWorksCorrectly(unittest.TestCase):

  def setUp(self):
    repo_path1 = pkg_resources.resource_filename('tests', 'data/example_repo/')
    repo_path2 = pkg_resources.resource_filename('tests', 'data/example_repo2/')
    self.repository = config.Config([repo_path1, repo_path2])
    self.config = self.repository.load_config()

    # output config for debugging purposes
    #from pprint import pformat
    #print(pformat(self.config))
    #print()

  def test_profiles_merged(self):
    profiles = self.config['profiles']
    self.assertTrue(len(profiles) is 2, 'Only {} profile(s) found, expected 2'.format(str(len(profiles))))

  def test_modules_merged(self):
    modules = self.config['modules']
    self.assertTrue(len(modules) is 2, 'Only {} module(s) found, expected 2'.format(str(len(modules))))
  
  def test_config_value_was_overriden(self):
    value = self.config['tools']['override']
    self.assertEqual(value, 2)