<s> import io <EOL> import sys <EOL> import unittest <EOL> from unittest . mock import Mock <EOL> from unittest . mock import patch <EOL> from pico8 import util <EOL> class TestUtil ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . orig_write_stream = util . _write_stream <EOL> self . orig_error_stream = util . _error_stream <EOL> util . _write_stream = io . StringIO ( ) <EOL> util . _error_stream = io . StringIO ( ) <EOL> def tearDown ( self ) : <EOL> util . _verbosity = util . VERBOSITY_NORMAL <EOL> util . _write_stream = self . orig_write_stream <EOL> util . _error_stream = self . orig_error_stream <EOL> def testWrite ( self ) : <EOL> s = '<STR_LIT>' <EOL> util . write ( s ) <EOL> self . assertEqual ( s , util . _write_stream . getvalue ( ) ) <EOL> def testWriteQuiet ( self ) : <EOL> util . set_verbosity ( util . VERBOSITY_QUIET ) <EOL> s = '<STR_LIT>' <EOL> util . write ( s ) <EOL> self . assertEqual ( '<STR_LIT>' , util . _write_stream . getvalue ( ) ) <EOL> def testError ( self ) : <EOL> s = '<STR_LIT>' <EOL> util . error ( s ) <EOL> self . assertEqual ( s , util . _error_stream . getvalue ( ) ) <EOL> def testErrorQuiet ( self ) : <EOL> s = '<STR_LIT>' <EOL> util . set_verbosity ( util . VERBOSITY_QUIET ) <EOL> util . error ( s ) <EOL> self . assertEqual ( s , util . _error_stream . getvalue ( ) ) <EOL> def testDebug ( self ) : <EOL> s = '<STR_LIT>' <EOL> util . debug ( s ) <EOL> self . assertEqual ( '<STR_LIT>' , util . _write_stream . getvalue ( ) ) <EOL> def testDebugVerbose ( self ) : <EOL> s = '<STR_LIT>' <EOL> util . set_verbosity ( util . VERBOSITY_DEBUG ) <EOL> util . debug ( s ) <EOL> self . assertEqual ( s , util . _write_stream . getvalue ( ) ) <EOL> class DummySection ( util . BaseSection ) : <EOL> HEX_LINE_LENGTH_BYTES = <NUM_LIT:3> <EOL> class TestBaseSection ( unittest . TestCase ) : <EOL> def testInit ( self ) : <EOL> s = DummySection ( b'<STR_LIT>' , <NUM_LIT:4> ) <EOL> self . assertEqual ( b'<STR_LIT>' , s . _data ) <EOL> self . assertEqual ( <NUM_LIT:4> , s . _version ) <EOL> def testFromLines ( self ) : <EOL> lines = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> s = DummySection . from_lines ( lines , <NUM_LIT:4> ) <EOL> self . assertEqual ( b'<STR_LIT>' , s . _data ) <EOL> self . assertEqual ( <NUM_LIT:4> , s . _version ) <EOL> def testFromBytes ( self ) : <EOL> s = DummySection . from_bytes ( b'<STR_LIT>' , <NUM_LIT:4> ) <EOL> self . assertEqual ( b'<STR_LIT>' , s . _data ) <EOL> self . assertEqual ( <NUM_LIT:4> , s . _version ) <EOL> def testToLines ( self ) : <EOL> s = DummySection . from_bytes ( b'<STR_LIT>' , <NUM_LIT:4> ) <EOL> lines = list ( s . to_lines ( ) ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , lines ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
