• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18import unittest
19
20from runner.chapters import Chapters, IncorrectFileFormatChapterException
21
22
23class ChapterNegativeCases(unittest.TestCase):
24    current_folder = os.path.dirname(__file__)
25
26    def test_unknown(self) -> None:
27        with self.assertRaises(FileNotFoundError):
28            Chapters('does-not-exist.yaml')
29
30    def test_no_chapters(self) -> None:
31        with self.assertRaises(IncorrectFileFormatChapterException):
32            Chapters(os.path.join(self.current_folder, 'chapters_neg_1_test.yaml'))
33
34    def test_no_semicolon(self) -> None:
35        with self.assertRaises(IncorrectFileFormatChapterException):
36            Chapters(os.path.join(self.current_folder, 'chapters_neg_2_test.yaml'))
37
38    def test_incorr_exclude_01(self) -> None:
39        with self.assertRaises(IncorrectFileFormatChapterException):
40            Chapters(os.path.join(self.current_folder, 'chapters_neg_3_test.yaml'))
41
42    def test_incorr_exclude_02(self) -> None:
43        # Missed ':' results in parsing of entire exclude list as one include item.
44        # This is YAML parser behaviour
45        test_file = os.path.join(self.current_folder, 'chapters_neg_4_test.yaml')
46        test_chapter = 'ch1'
47        chapters = Chapters(test_file)
48        ch1 = chapters.chapters.get(test_chapter)
49        if ch1:
50            len_includes = len(ch1.includes)
51            len_excludes = len(ch1.excludes)
52            self.assertEqual(len_includes, 2)
53            self.assertEqual(len_excludes, 0)
54        else:
55            self.assertIsNotNone(ch1, f"Chapter '{test_chapter}' is absent in '{test_file}'")
56