1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# 5# Copyright 2017, Data61 6# Commonwealth Scientific and Industrial Research Organisation (CSIRO) 7# ABN 41 687 119 230. 8# 9# This software may be distributed and modified according to the terms of 10# the BSD 2-Clause license. Note that NO WARRANTY is provided. 11# See "LICENSE_BSD2.txt" for details. 12# 13# @TAG(DATA61_BSD) 14# 15 16from __future__ import absolute_import, division, print_function, \ 17 unicode_literals 18 19import os, six, sys, unittest 20 21ME = os.path.abspath(__file__) 22 23# Make CAmkES importable 24sys.path.append(os.path.join(os.path.dirname(ME), '../../..')) 25 26from camkes.internal.tests.utils import CAmkESTest 27from camkes.parser import ParseError 28 29class TestObjects(CAmkESTest): 30 def test_basic_parse_error(self): 31 with self.assertRaises(ParseError): 32 raise ParseError('hello world') 33 34 def test_parse_error_message(self): 35 with six.assertRaisesRegex(self, ParseError, '.*hello world.*'): 36 raise ParseError('hello world') 37 38 def test_parse_error_filename(self): 39 with six.assertRaisesRegex(self, ParseError, '^myfile:.*hello world.*'): 40 raise ParseError('hello world', filename='myfile') 41 42 def test_parse_error_lineno(self): 43 with six.assertRaisesRegex(self, ParseError, '.*10:.*hello world.*'): 44 raise ParseError('hello world', lineno=10) 45 46 def test_parse_error_filename_lineno(self): 47 with six.assertRaisesRegex(self, ParseError, '^myfile:.*10:.*hello world.*'): 48 raise ParseError('hello world', filename='myfile', lineno=10) 49 50if __name__ == '__main__': 51 unittest.main() 52