<s> '''<STR_LIT>''' <EOL> import os <EOL> import unittest <EOL> try : <EOL> from unittest . mock import patch <EOL> except : <EOL> from mock import patch <EOL> from kivy . utils import ( boundary , escape_markup , format_bytes_to_human , <EOL> is_color_transparent , SafeList , get_random_color , get_hex_from_color , <EOL> get_color_from_hex , strtotuple , QueryDict , intersection , difference , <EOL> interpolate , Platform , deprecated , reify ) <EOL> from kivy import utils <EOL> class UtilsTest ( unittest . TestCase ) : <EOL> def test_escape_markup ( self ) : <EOL> escaped = escape_markup ( '<STR_LIT>' ) <EOL> self . assertEqual ( escaped , '<STR_LIT>' ) <EOL> def test_format_bytes_to_human ( self ) : <EOL> a = format_bytes_to_human ( <NUM_LIT> ) <EOL> self . assertEqual ( a , '<STR_LIT>' ) <EOL> b = format_bytes_to_human ( <NUM_LIT> , precision = <NUM_LIT:4> ) <EOL> self . assertEqual ( b , '<STR_LIT>' ) <EOL> c = format_bytes_to_human ( <NUM_LIT> ) <EOL> self . assertEqual ( c , '<STR_LIT>' ) <EOL> def test_boundary ( self ) : <EOL> x = boundary ( - <NUM_LIT:1000> , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> self . assertEqual ( x , <NUM_LIT:0> ) <EOL> x = boundary ( <NUM_LIT:1000> , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> self . assertEqual ( x , <NUM_LIT:100> ) <EOL> x = boundary ( <NUM_LIT:50> , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> self . assertEqual ( x , <NUM_LIT:50> ) <EOL> def test_is_color_transparent ( self ) : <EOL> c = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> self . assertFalse ( is_color_transparent ( c ) ) <EOL> c = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> self . assertFalse ( is_color_transparent ( c ) ) <EOL> c = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> self . assertTrue ( is_color_transparent ( c ) ) <EOL> @ deprecated <EOL> def a_deprecated_function ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_deprecated ( self ) : <EOL> self . a_deprecated_function ( ) <EOL> def test_SafeList_iterate ( self ) : <EOL> sl = SafeList ( [ '<STR_LIT:1>' , <NUM_LIT:2> , <NUM_LIT> ] ) <EOL> self . assertTrue ( isinstance ( sl , list ) ) <EOL> it = sl . iterate ( ) <EOL> self . assertEqual ( next ( it ) , '<STR_LIT:1>' ) <EOL> self . assertEqual ( next ( it ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( next ( it ) , <NUM_LIT> ) <EOL> def test_SafeList_iterate_reverse ( self ) : <EOL> sl = SafeList ( [ '<STR_LIT:1>' , <NUM_LIT:2> , <NUM_LIT> ] ) <EOL> self . assertTrue ( isinstance ( sl , list ) ) <EOL> it = sl . iterate ( reverse = True ) <EOL> self . assertEqual ( next ( it ) , <NUM_LIT> ) <EOL> self . assertEqual ( next ( it ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( next ( it ) , '<STR_LIT:1>' ) <EOL> def test_SafeList_clear ( self ) : <EOL> sl = SafeList ( [ '<STR_LIT:1>' , <NUM_LIT:2> , <NUM_LIT> ] ) <EOL> self . assertTrue ( isinstance ( sl , list ) ) <EOL> sl . clear ( ) <EOL> self . assertEqual ( len ( sl ) , <NUM_LIT:0> ) <EOL> def test_get_random_color_fixed_alpha ( self ) : <EOL> actual = get_random_color ( ) <EOL> self . assertEqual ( len ( actual ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( actual [ <NUM_LIT:3> ] , <NUM_LIT:1.> ) <EOL> actual = get_random_color ( alpha = <NUM_LIT> ) <EOL> self . assertEqual ( len ( actual ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( actual [ <NUM_LIT:3> ] , <NUM_LIT> ) <EOL> def test_get_random_color_random_alpha ( self ) : <EOL> actual = get_random_color ( alpha = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( actual ) , <NUM_LIT:4> ) <EOL> def test_get_hex_from_color_noalpha ( self ) : <EOL> actual = get_hex_from_color ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( actual , expected ) <EOL> def test_get_hex_from_color_alpha ( self ) : <EOL> actual = get_hex_from_color ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( actual , expected ) <EOL> def test_get_color_from_hex_noalpha ( self ) : <EOL> actual = get_color_from_hex ( '<STR_LIT>' ) <EOL> expected = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> self . assertAlmostEqual ( actual [ i ] , expected [ i ] ) <EOL> def test_get_color_from_hex_alpha ( self ) : <EOL> actual = get_color_from_hex ( '<STR_LIT>' ) <EOL> expected = [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> self . assertAlmostEqual ( actual [ i ] , expected [ i ] ) <EOL> def test_strtotuple ( self ) : <EOL> self . assertRaises ( Exception , strtotuple , '<STR_LIT>' ) <EOL> self . assertRaises ( Exception , strtotuple , '<STR_LIT>' ) <EOL> self . assertRaises ( Exception , strtotuple , '<STR_LIT>' ) <EOL> self . assertRaises ( Exception , strtotuple , '<STR_LIT>' ) <EOL> actual = strtotuple ( '<STR_LIT>' ) <EOL> expected = ( <NUM_LIT:12> , <NUM_LIT:8> , <NUM_LIT> ) <EOL> self . assertEqual ( actual , expected ) <EOL> def test_QueryDict ( self ) : <EOL> qd = QueryDict ( ) <EOL> self . assertTrue ( isinstance ( qd , dict ) ) <EOL> qd . toto = <NUM_LIT:1> <EOL> self . assertEqual ( qd . get ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> toto = qd . toto <EOL> self . assertEqual ( toto , <NUM_LIT:1> ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> foo = qd . not_an_attribute <EOL> def test_intersection ( self ) : <EOL> abcd = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] <EOL> efgh = [ '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' , '<STR_LIT:h>' ] <EOL> fedc = [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] <EOL> feed = [ '<STR_LIT:f>' , '<STR_LIT:e>' , '<STR_LIT:e>' , '<STR_LIT:d>' ] <EOL> self . assertEqual ( intersection ( abcd , efgh ) , [ ] ) <EOL> self . assertEqual ( intersection ( abcd , fedc ) , [ '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> self . assertEqual ( intersection ( feed , feed ) , feed ) <EOL> self . assertEqual ( intersection ( [ ] , [ ] ) , [ ] ) <EOL> self . assertEqual ( intersection ( feed , fedc ) , feed ) <EOL> self . assertEqual ( intersection ( fedc , feed ) , [ '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] ) <EOL> self . assertEqual ( intersection ( feed , efgh ) , [ '<STR_LIT:f>' , '<STR_LIT:e>' , '<STR_LIT:e>' ] ) <EOL> def test_difference ( self ) : <EOL> abcd = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] <EOL> efgh = [ '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' , '<STR_LIT:h>' ] <EOL> fedc = [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] <EOL> feed = [ '<STR_LIT:f>' , '<STR_LIT:e>' , '<STR_LIT:e>' , '<STR_LIT:d>' ] <EOL> self . assertEqual ( difference ( abcd , efgh ) , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> self . assertEqual ( difference ( efgh , fedc ) , [ '<STR_LIT:g>' , '<STR_LIT:h>' ] ) <EOL> self . assertEqual ( difference ( [ ] , [ ] ) , [ ] ) <EOL> self . assertEqual ( difference ( abcd , abcd ) , [ ] ) <EOL> self . assertEqual ( difference ( fedc , feed ) , [ '<STR_LIT:c>' ] ) <EOL> self . assertEqual ( difference ( feed , abcd ) , [ '<STR_LIT:f>' , '<STR_LIT:e>' , '<STR_LIT:e>' ] ) <EOL> self . assertEqual ( difference ( abcd , feed ) , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> def test_interpolate_solo ( self ) : <EOL> values = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> a = <NUM_LIT:0.> <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> a = interpolate ( a , <NUM_LIT:100> ) <EOL> self . assertEqual ( a , values [ i ] ) <EOL> def test_interpolate_multi ( self ) : <EOL> x = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> y = [ - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> ] <EOL> p = <NUM_LIT:0.> , <NUM_LIT:0.> <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> p = interpolate ( p , [ <NUM_LIT:100> , - <NUM_LIT:100> ] ) <EOL> self . assertEqual ( p , [ x [ i ] , y [ i ] ] ) <EOL> @ reify <EOL> def fib_100 ( self ) : <EOL> """<STR_LIT>""" <EOL> a , b = <NUM_LIT:0> , <NUM_LIT:1> <EOL> for n in range ( <NUM_LIT:2> , <NUM_LIT> ) : <EOL> a , b = b , a + b <EOL> return b <EOL> def test_reify ( self ) : <EOL> first = self . fib_100 <EOL> second = self . fib_100 <EOL> assert first == second <EOL> def test_Platform ( self ) : <EOL> pf = Platform <EOL> pf ( ) <EOL> hash ( pf ) <EOL> repr ( pf ) <EOL> def test_Platform_android ( self ) : <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> pf = Platform ( ) <EOL> self . assertTrue ( pf == '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , os . environ ) <EOL> def test_Platform_ios ( self ) : <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> pf = Platform ( ) <EOL> self . assertEqual ( str ( pf ) , '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , os . environ ) <EOL> def test_Platform_win32 ( self ) : <EOL> self . _test_platforms ( '<STR_LIT:win32>' , '<STR_LIT>' ) <EOL> def test_Platform_cygwin ( self ) : <EOL> self . _test_platforms ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_Platform_linux2 ( self ) : <EOL> self . _test_platforms ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_Platform_darwin ( self ) : <EOL> self . _test_platforms ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_Platform_freebsd ( self ) : <EOL> self . _test_platforms ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_Platform_unknown ( self ) : <EOL> self . _test_platforms ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _test_platforms ( self , input , testval ) : <EOL> utils . _sys_platform = input <EOL> pf = Platform ( ) <EOL> self . assertTrue ( pf == testval ) </s>
