<s> from __future__ import ( absolute_import , division , print_function , <EOL> unicode_literals ) <EOL> from . import cleanup , get_assert_same_ggplot <EOL> assert_same_ggplot = get_assert_same_ggplot ( __file__ ) <EOL> from nose . tools import assert_true , assert_raises <EOL> from ggplot import * <EOL> import matplotlib . pyplot as plt <EOL> @ cleanup <EOL> def test_not_turn_off_first_axis ( ) : <EOL> import pandas as pd <EOL> dat4 = pd . DataFrame ( { '<STR_LIT:x>' : range ( <NUM_LIT> ) , '<STR_LIT:y>' : range ( <NUM_LIT> ) , '<STR_LIT:w>' : ( list ( '<STR_LIT>' ) * <NUM_LIT:10> ) } ) <EOL> gg = ggplot ( aes ( x = '<STR_LIT:x>' , y = '<STR_LIT:y>' ) , data = dat4 ) + geom_line ( ) + facet_wrap ( '<STR_LIT:w>' ) <EOL> assert_same_ggplot ( gg , "<STR_LIT>" ) <EOL> @ cleanup <EOL> def test_scale_facet_wrap_visual ( ) : <EOL> p = ggplot ( aes ( x = "<STR_LIT>" ) , data = diamonds ) + geom_histogram ( ) <EOL> assert_same_ggplot ( p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> assert_same_ggplot ( p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> assert_same_ggplot ( p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> assert_same_ggplot ( p + facet_wrap ( "<STR_LIT>" , scales = None ) , "<STR_LIT:none>" ) <EOL> def test_scale_facet_wrap_exception ( ) : <EOL> with assert_raises ( Exception ) : <EOL> facet_wrap ( ) <EOL> def test_add_scale_returns_new_ggplot_object ( ) : <EOL> p = ggplot ( aes ( x = "<STR_LIT>" ) , data = diamonds ) + geom_histogram ( ) <EOL> c , r = p . n_columns , p . n_rows <EOL> p2 = p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) <EOL> cn , rn = p . n_columns , p . n_rows <EOL> c2 , r2 = p2 . n_columns , p2 . n_rows <EOL> assert_true ( c == cn and r == rn , "<STR_LIT>" ) <EOL> assert_true ( c != c2 or r != r2 , "<STR_LIT>" ) <EOL> @ cleanup <EOL> def test_scale_facet_wrap_internals ( ) : <EOL> def convertText ( t ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return float ( t . get_text ( ) ) <EOL> except : <EOL> return <NUM_LIT:0> <EOL> def empty ( t ) : <EOL> """<STR_LIT>""" <EOL> return len ( t . get_text ( ) . strip ( ) ) == <NUM_LIT:0> <EOL> p = ggplot ( aes ( x = "<STR_LIT>" ) , data = diamonds ) + geom_histogram ( ) <EOL> p2 = p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) <EOL> print ( p2 ) <EOL> columns = p2 . n_columns <EOL> fig = plt . gcf ( ) <EOL> for ax in fig . axes : <EOL> assert_true ( len ( ax . get_xticklabels ( ) ) > <NUM_LIT:0> ) <EOL> assert_true ( len ( ax . get_yticklabels ( ) ) > <NUM_LIT:0> ) <EOL> print ( p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) ) <EOL> fig = plt . gcf ( ) <EOL> yticks = fig . axes [ <NUM_LIT:0> ] . get_yticks ( ) <EOL> for pos , ax in enumerate ( fig . axes ) : <EOL> assert_true ( all ( ax . get_yticks ( ) == yticks ) ) <EOL> if pos % columns == <NUM_LIT:0> : <EOL> assert_true ( all ( list ( map ( convertText , ax . get_yticklabels ( ) ) ) == yticks ) ) <EOL> else : <EOL> assert_true ( all ( map ( empty , ax . get_yticklabels ( ) ) ) ) <EOL> assert_true ( len ( ax . get_xticklabels ( ) ) > <NUM_LIT:0> ) <EOL> print ( p + facet_wrap ( "<STR_LIT>" , scales = "<STR_LIT>" ) ) <EOL> fig = plt . gcf ( ) <EOL> xticks = fig . axes [ <NUM_LIT:0> ] . get_xticks ( ) <EOL> subplots = len ( fig . axes ) <EOL> for pos , ax in enumerate ( fig . axes ) : <EOL> assert_true ( all ( ax . get_xticks ( ) == xticks ) ) <EOL> if subplots - pos > columns : <EOL> assert_true ( all ( map ( empty , ax . get_xticklabels ( ) ) ) ) <EOL> else : <EOL> assert_true ( all ( list ( map ( convertText , ax . get_xticklabels ( ) ) ) == xticks ) ) <EOL> assert_true ( len ( ax . get_yticklabels ( ) ) > <NUM_LIT:0> ) <EOL> print ( p + facet_wrap ( "<STR_LIT>" , scales = None ) ) <EOL> fig = plt . gcf ( ) <EOL> xticks = fig . axes [ <NUM_LIT:0> ] . get_xticks ( ) <EOL> yticks = fig . axes [ <NUM_LIT:0> ] . get_yticks ( ) <EOL> for pos , ax in enumerate ( fig . axes ) : <EOL> assert_true ( all ( ax . get_xticks ( ) == xticks ) ) <EOL> assert_true ( all ( ax . get_yticks ( ) == yticks ) ) <EOL> if subplots - pos > columns : <EOL> assert_true ( all ( map ( empty , ax . get_xticklabels ( ) ) ) ) <EOL> else : <EOL> assert_true ( all ( list ( map ( convertText , ax . get_xticklabels ( ) ) ) == xticks ) ) <EOL> if pos % columns == <NUM_LIT:0> : <EOL> assert_true ( all ( list ( map ( convertText , ax . get_yticklabels ( ) ) ) == yticks ) ) <EOL> else : <EOL> assert_true ( all ( map ( empty , ax . get_yticklabels ( ) ) ) ) </s>
