1#!/usr/bin/env python3
2
3# Copyright (C) 2016 Intel Corporation
4#
5# SPDX-License-Identifier: MIT
6#
7
8import unittest
9import logging
10import os
11
12from common import setup_sys_path, TestBase
13setup_sys_path()
14
15from oeqa.core.exception import OEQAMissingVariable
16from oeqa.core.utils.test import getCaseMethod, getSuiteCasesNames
17
18class TestData(TestBase):
19    modules = ['data']
20
21    def test_data_fail_missing_variable(self):
22        expectedException = "oeqa.core.exception.OEQAMissingVariable"
23
24        tc = self._testLoader(modules=self.modules)
25        results = tc.runTests()
26        self.assertFalse(results.wasSuccessful())
27        for test, data in results.errors:
28            expect = False
29            if expectedException in data:
30                expect = True
31
32            self.assertTrue(expect)
33
34    def test_data_fail_wrong_variable(self):
35        expectedError = 'AssertionError'
36        d = {'IMAGE' : 'core-image-sato', 'ARCH' : 'arm'}
37
38        tc = self._testLoader(d=d, modules=self.modules)
39        results = tc.runTests()
40        self.assertFalse(results.wasSuccessful())
41        for test, data in results.failures:
42            expect = False
43            if expectedError in data:
44                expect = True
45
46            self.assertTrue(expect)
47
48    def test_data_ok(self):
49        d = {'IMAGE' : 'core-image-minimal', 'ARCH' : 'x86', 'MACHINE' : 'qemuarm'}
50
51        tc = self._testLoader(d=d, modules=self.modules)
52        self.assertEqual(True, tc.runTests().wasSuccessful())
53
54if __name__ == '__main__':
55    unittest.main()
56