<s> import unittest <EOL> import os <EOL> from robot . errors import DataError <EOL> from robot . writer . datafilewriter import WritingContext <EOL> from robot . parsing . model import TestCaseFile <EOL> from robot . utils . asserts import assert_equal , assert_raises <EOL> HTML_SOURCE = os . path . abspath ( '<STR_LIT>' ) <EOL> TXT_SOURCE = os . path . abspath ( '<STR_LIT>' ) <EOL> class TestOutputFile ( unittest . TestCase ) : <EOL> def test_source_file_is_used_by_default ( self ) : <EOL> self . _assert_output_file ( HTML_SOURCE , source = HTML_SOURCE ) <EOL> def test_given_format_overrides_source_extension ( self ) : <EOL> self . _assert_output_file ( TXT_SOURCE , HTML_SOURCE , format = '<STR_LIT>' ) <EOL> def _assert_output_file ( self , expected , source = None , format = '<STR_LIT>' ) : <EOL> ctx = WritingContext ( TestCaseFile ( source = source ) , format = format ) <EOL> assert_equal ( ctx . _output_path ( ) , expected ) <EOL> class TestFormat ( unittest . TestCase ) : <EOL> def test_format_from_source_file_is_used_by_default ( self ) : <EOL> self . _assert_format ( '<STR_LIT:html>' , source = HTML_SOURCE ) <EOL> def test_explicit_format_overrides_default ( self ) : <EOL> self . _assert_format ( '<STR_LIT>' , source = HTML_SOURCE , format = '<STR_LIT>' ) <EOL> def test_creating_with_invalid_format_fails ( self ) : <EOL> assert_raises ( DataError , WritingContext , datafile = None , format = '<STR_LIT>' ) <EOL> def _assert_format ( self , expected , source , format = '<STR_LIT>' ) : <EOL> data = TestCaseFile ( source = source ) <EOL> ctx = WritingContext ( data , format = format ) <EOL> assert_equal ( ctx . format , expected ) </s>
