# How to use test3 method in avocado

Best Python code snippet using avocado_python

manual_test_gpa.py

Source:manual_test_gpa.py

`1# Test of GPA Module2import numpy as np3import math as math4import data as data5import gpa as gpa6import matplotlib.pyplot as plt7import statistics8# #######################################9# Test #2 in TestPlan document10# #######################################11data_test_2 = data.SMGData() # Data structure for test 212# Generated STEM Moire hologram (256x256 pixels) using numpy arrays with a unique periodicity of 16 pixels along13# horizontal axis. (Very easy test case)14x2 = np.linspace(0, 255, 256)15y2 = np.linspace(0, 255, 256)16mx2, my2 = np.meshgrid(x2, y2)17ismh2 = np.sin(mx2 * 2 * np.pi / 16)18ft_ismh2 = np.fft.fft2(ismh2)19# Store data in datastructure20data_test_2.store('ISMHexp', ismh2)21data_test_2.store('FTISMHexp', ft_ismh2)22# Create branch for mask23data_test_2.create_branch('Mask1')24# Circle of radius 1 centered around coordinate (192, 128)25r2 = 126center2 = (144, 128)27circle2 = center2, r228# Store mask properties into datastructure29data_test_2.store_g('Mask1', 'Mask', circle2)30# Entering gpa31gpa.gpa('Mask1', data_test_2)32# Display data33# Input/Output data - Phase is supposed to be constant and equal to 0, anything different from 0 represents the error.34fig_test2 = plt.figure(figsize=(13, 9))35fig_test2_ax1 = fig_test2.add_subplot(2, 3, 1)36fig_test2_ax2 = fig_test2.add_subplot(2, 3, 4)37fig_test2_ax3 = fig_test2.add_subplot(2, 3, 2)38fig_test2_ax4 = fig_test2.add_subplot(2, 3, 5)39fig_test2_ax5 = fig_test2.add_subplot(2, 3, 3)40fig_test2_ax6 = fig_test2.add_subplot(2, 3, 6)41fig_test2_ax1.imshow(ismh2, cmap='gray')42fig_test2_ax1.set_title('I_SMH')43fig_test2_ax2.imshow(np.log1p(np.fft.fftshift(np.abs(ft_ismh2 ** 2))), cmap='gray')44fig_test2_ax2.set_title('Fourier Transform of I_SMH')45fig_test2_ax3.imshow(data_test_2.load_g('Mask1', 'phaseraw'), cmap='gray', vmin=-np.pi, vmax=np.pi)46fig_test2_ax3.set_title('Raw Phase')47fig_test2_ax4.imshow(data_test_2.load_g('Mask1', 'phasegM'), cmap='gray', vmin=-np.pi, vmax=np.pi)48fig_test2_ax4.set_title('Phase corrected')49fig_test2_ax5.imshow(data_test_2.load_g('Mask1', 'deltagM')[0], cmap='gray', vmin=-1, vmax=1)50fig_test2_ax5.set_title('Vertical component of Îg')51fig_test2_ax6.imshow(data_test_2.load_g('Mask1', 'deltagM')[1], cmap='gray', vmin=-1, vmax=1)52fig_test2_ax6.set_title('Horizontal component of Îg')53fig_test2.savefig('/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/'54 'Test_2_explanation.png', dpi=300, bbox_inches='tight')55# Input/Output data in 1D56fig_test2_1d = plt.figure(figsize=(13, 9))57fig_test2_1d_ax1 = fig_test2_1d.add_subplot(2, 3, 1)58fig_test2_1d_ax2 = fig_test2_1d.add_subplot(2, 3, 4)59fig_test2_1d_ax3 = fig_test2_1d.add_subplot(2, 3, 2)60fig_test2_1d_ax4 = fig_test2_1d.add_subplot(2, 3, 5)61fig_test2_1d_ax5 = fig_test2_1d.add_subplot(2, 3, 3)62fig_test2_1d_ax6 = fig_test2_1d.add_subplot(2, 3, 6)63fig_test2_1d_ax1.plot(ismh2[128, :])64fig_test2_1d_ax1.set_title('I_SMH')65fig_test2_1d_ax2.plot(x2, np.log1p(np.fft.fftshift(np.abs(ft_ismh2 ** 2)))[128, :])66fig_test2_1d_ax2.set_title('Fourier Transform of I_SMH')67fig_test2_1d_ax3.plot(x2, data_test_2.load_g('Mask1', 'phaseraw')[128, :])68fig_test2_1d_ax3.set_ylim(-np.pi, np.pi)69fig_test2_1d_ax3.set_title('Raw Phase')70fig_test2_1d_ax4.plot(x2, data_test_2.load_g('Mask1', 'phasegM')[128, :])71fig_test2_1d_ax4.set_ylim(-np.pi, np.pi)72fig_test2_1d_ax4.set_title('Phase corrected')73fig_test2_1d_ax5.plot(x2, data_test_2.load_g('Mask1', 'deltagM')[0, 128, :])74fig_test2_1d_ax5.set_ylim(-1, 1)75fig_test2_1d_ax5.set_title('Vertical component of Îg')76fig_test2_1d_ax6.plot(x2, data_test_2.load_g('Mask1', 'deltagM')[1, 128, :])77fig_test2_1d_ax6.set_ylim(-1, 1)78fig_test2_1d_ax6.set_title('Horizontal component of Îg')79fig_test2_1d.savefig('/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/'80 'Test_2_explanation_1D.png', dpi=300, bbox_inches='tight')81plt.show()82# -------------------- Test #2 Improvement ---------------83# periodicity in pixels: q84q = [3, 4, 4.1, 4.2, 4.5, 16, 100]85data2 = []86for periodicity in q:87 ismh = np.sin(mx2 * 2 * np.pi / periodicity)88 ft_ismh = np.fft.fft2(ismh)89 circle = (128 + round(256 / periodicity), 128), r290 data_i = data.SMGData()91 data_i.store('ISMHexp', ismh)92 data_i.store('FTISMHexp', ft_ismh)93 data_i.create_branch('Mask1')94 data_i.store_g('Mask1', 'Mask', circle)95 gpa.gpa('Mask1', data_i)96 data2.append(data_i)97fig_test2_multiple_q = plt.figure(figsize=(13, 6))98fig_test2_multiple_q_ax1 = fig_test2_multiple_q.add_subplot(1, 2, 1)99fig_test2_multiple_q_ax2 = fig_test2_multiple_q.add_subplot(1, 2, 2)100fig_test2_multiple_q_ismh = plt.figure(figsize=(13, 6))101fig_test2_multiple_q_ismh_ax1 = fig_test2_multiple_q_ismh.add_subplot(1, 2, 1)102fig_test2_multiple_q_ismh_ax2 = fig_test2_multiple_q_ismh.add_subplot(1, 2, 2)103fig_test2_error_delta_g = plt.figure(figsize=(13, 9))104fig_test2_error_delta_g_ax = fig_test2_error_delta_g.add_subplot(1, 1, 1)105count = 0106mean_test_2 = []107stand_dev_test_2 = []108for elements in data2:109 fig_test2_multiple_q_ax1.plot(x2, elements.load_g('Mask1', 'phasegM')[128, :], linewidth=3, label=str(q[count]))110 fig_test2_multiple_q_ax2.plot(x2, elements.load_g('Mask1', 'deltagM')[1, 128, :], linewidth=3, label=str(q[count]))111 fig_test2_multiple_q_ismh_ax1.plot(x2[160:180], elements.load('ISMHexp')[128, 160:180], linewidth=3,112 label=str(q[count]))113 fig_test2_multiple_q_ismh_ax2.plot(x2, np.log1p(np.fft.fftshift(np.abs(elements.load('FTISMHexp') ** 2)))[128, :],114 linewidth=3, label=str(q[count]))115 error_delta_g = np.abs(elements.load_g('Mask1', 'deltagM')[1, 128, :])116 fig_test2_error_delta_g_ax.plot(x2, error_delta_g, linewidth=3, label=str(q[count]))117 mean_test_2.append(statistics.mean(elements.load_g('Mask1', 'deltagM')[1, 128, :]))118 stand_dev_test_2.append(statistics.stdev(elements.load_g('Mask1', 'deltagM')[1, 128, :]))119 count += 1120fig_test2_multiple_q_ax1.set_ylim(-np.pi, np.pi)121fig_test2_multiple_q_ax1.legend()122fig_test2_multiple_q_ax1.set_title('Phase corrected')123fig_test2_multiple_q_ax2.set_title('Horizontal component of Îg')124fig_test2_multiple_q_ax2.set_ylim(-0.01, 0.01)125fig_test2_multiple_q_ismh_ax1.set_title('I_SMH')126fig_test2_multiple_q_ismh_ax2.set_title('Fourier Transform of I_SMH')127fig_test2_multiple_q_ismh_ax2.legend()128fig_test2_error_delta_g_ax.set_ylim(0, 0.0025)129fig_test2_error_delta_g_ax.legend()130fig_test2_error_delta_g_ax.set_title('Error of the horizontal component of Îg ')131fig_test2_multiple_q.savefig(132 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_test_results.png',133 dpi=300, bbox_inches='tight')134fig_test2_multiple_q_ismh.savefig(135 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_test_cases.png',136 dpi=300, bbox_inches='tight')137fig_test2_error_delta_g.savefig(138 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_test_error.png',139 dpi=300, bbox_inches='tight')140plt.show()141print('Mean test 2 = ', mean_test_2)142print('StDev test 2 = ', stand_dev_test_2)143# -------------------- Testing the vertical direction -------------------144data_test_2_v = data.SMGData() # Data structure for test 2145# Generated STEM Moire hologram (256x256 pixels) using numpy arrays with a unique periodicity of 16 pixels along146# horizontal axis. (Very easy test case)147x2_v = np.linspace(0, 255, 256)148y2_v = np.linspace(0, 255, 256)149mx2_v, my2_v = np.meshgrid(x2_v, y2_v)150ismh2_v = np.sin(my2_v * 2 * np.pi / 16)151ft_ismh2_v = np.fft.fft2(ismh2_v)152# Store data in datastructure153data_test_2_v.store('ISMHexp', ismh2_v)154data_test_2_v.store('FTISMHexp', ft_ismh2_v)155# Create branch for mask156data_test_2_v.create_branch('Mask1')157# Circle of radius 1 centered around coordinate (192, 128)158r2_v = 1159center2_v = (128, 144)160circle2_v = center2_v, r2_v161# Store mask properties into datastructure162data_test_2_v.store_g('Mask1', 'Mask', circle2_v)163# Entering gpa164gpa.gpa('Mask1', data_test_2_v)165# Display data166# Input/Output data - Phase is supposed to be constant and equal to 0, anything different from 0 represents the error.167fig_test2_v = plt.figure(figsize=(13, 9))168fig_test2_ax1_v = fig_test2_v.add_subplot(2, 3, 1)169fig_test2_ax2_v = fig_test2_v.add_subplot(2, 3, 4)170fig_test2_ax3_v = fig_test2_v.add_subplot(2, 3, 2)171fig_test2_ax4_v = fig_test2_v.add_subplot(2, 3, 5)172fig_test2_ax5_v = fig_test2_v.add_subplot(2, 3, 3)173fig_test2_ax6_v = fig_test2_v.add_subplot(2, 3, 6)174fig_test2_ax1_v.imshow(ismh2_v, cmap='gray')175fig_test2_ax1_v.set_title('I_SMH')176fig_test2_ax2_v.imshow(np.log1p(np.fft.fftshift(np.abs(ft_ismh2_v ** 2))), cmap='gray')177fig_test2_ax2_v.set_title('Fourier Transform of I_SMH')178fig_test2_ax3_v.imshow(data_test_2_v.load_g('Mask1', 'phaseraw'), cmap='gray', vmin=-np.pi, vmax=np.pi)179fig_test2_ax3_v.set_title('Raw Phase')180fig_test2_ax4_v.imshow(data_test_2_v.load_g('Mask1', 'phasegM'), cmap='gray', vmin=-np.pi, vmax=np.pi)181fig_test2_ax4_v.set_title('Phase corrected')182fig_test2_ax5_v.imshow(data_test_2_v.load_g('Mask1', 'deltagM')[0], cmap='gray', vmin=-1, vmax=1)183fig_test2_ax5_v.set_title('Vertical component of Îg')184fig_test2_ax6_v.imshow(data_test_2_v.load_g('Mask1', 'deltagM')[1], cmap='gray', vmin=-1, vmax=1)185fig_test2_ax6_v.set_title('Horizontal component of Îg')186fig_test2_v.savefig(187 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_v_explanation.png',188 dpi=300, bbox_inches='tight')189# Input/Output data in 1D190fig_test2_1d_v = plt.figure(figsize=(13, 9))191fig_test2_1d_ax1_v = fig_test2_1d_v.add_subplot(2, 3, 1)192fig_test2_1d_ax2_v = fig_test2_1d_v.add_subplot(2, 3, 4)193fig_test2_1d_ax3_v = fig_test2_1d_v.add_subplot(2, 3, 2)194fig_test2_1d_ax4_v = fig_test2_1d_v.add_subplot(2, 3, 5)195fig_test2_1d_ax5_v = fig_test2_1d_v.add_subplot(2, 3, 3)196fig_test2_1d_ax6_v = fig_test2_1d_v.add_subplot(2, 3, 6)197fig_test2_1d_ax1_v.plot(ismh2_v[:, 128])198fig_test2_1d_ax1_v.set_title('I_SMH')199fig_test2_1d_ax2_v.plot(y2_v, np.log1p(np.fft.fftshift(np.abs(ft_ismh2_v ** 2)))[:, 128])200fig_test2_1d_ax2_v.set_title('Fourier Transform of I_SMH')201fig_test2_1d_ax3_v.plot(y2_v, data_test_2_v.load_g('Mask1', 'phaseraw')[:, 128])202fig_test2_1d_ax3_v.set_ylim(-np.pi, np.pi)203fig_test2_1d_ax3_v.set_title('Raw Phase')204fig_test2_1d_ax4_v.plot(y2_v, data_test_2_v.load_g('Mask1', 'phasegM')[:, 128])205fig_test2_1d_ax4_v.set_ylim(-np.pi, np.pi)206fig_test2_1d_ax4_v.set_title('Phase corrected')207fig_test2_1d_ax5_v.plot(y2_v, data_test_2_v.load_g('Mask1', 'deltagM')[0, :, 128])208fig_test2_1d_ax5_v.set_ylim(-1, 1)209fig_test2_1d_ax5_v.set_title('Vertical component of Îg')210fig_test2_1d_ax6_v.plot(y2_v, data_test_2_v.load_g('Mask1', 'deltagM')[1, :, 128])211fig_test2_1d_ax6_v.set_ylim(-1, 1)212fig_test2_1d_ax6_v.set_title('Horizontal component of Îg')213fig_test2_1d_v.savefig(214 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_v_explanation_1D.png',215 dpi=300, bbox_inches='tight')216plt.show()217# -------------------- Test #2 Improvement ---------------218# periodicity in pixels: q219q_v = [3, 4, 4.1, 4.2, 4.5, 16, 100]220data2_v = []221for periodicity in q_v:222 ismh_v = np.sin(my2_v * 2 * np.pi / periodicity)223 ft_ismh_v = np.fft.fft2(ismh_v)224 circle_v = (128, 128 + round(256 / periodicity)), r2_v225 data_i_v = data.SMGData()226 data_i_v.store('ISMHexp', ismh_v)227 data_i_v.store('FTISMHexp', ft_ismh_v)228 data_i_v.create_branch('Mask1')229 data_i_v.store_g('Mask1', 'Mask', circle_v)230 gpa.gpa('Mask1', data_i_v)231 data2_v.append(data_i_v)232fig_test2_multiple_q_v = plt.figure(figsize=(13, 6))233fig_test2_multiple_q_ax1_v = fig_test2_multiple_q_v.add_subplot(1, 2, 1)234fig_test2_multiple_q_ax2_v = fig_test2_multiple_q_v.add_subplot(1, 2, 2)235fig_test2_multiple_q_ismh_v = plt.figure(figsize=(13, 6))236fig_test2_multiple_q_ismh_ax1_v = fig_test2_multiple_q_ismh_v.add_subplot(1, 2, 1)237fig_test2_multiple_q_ismh_ax2_v = fig_test2_multiple_q_ismh_v.add_subplot(1, 2, 2)238fig_test2_error_delta_g_v = plt.figure(figsize=(13, 9))239fig_test2_error_delta_g_ax_v = fig_test2_error_delta_g_v.add_subplot(1, 1, 1)240count = 0241mean_test_2_v = []242stand_dev_test_2_v = []243for elements in data2_v:244 fig_test2_multiple_q_ax1_v.plot(y2_v, elements.load_g('Mask1', 'phasegM')[:, 128],245 linewidth=3, label=str(q[count]))246 fig_test2_multiple_q_ax2_v.plot(y2_v, elements.load_g('Mask1', 'deltagM')[0, :, 128],247 linewidth=3, label=str(q[count]))248 fig_test2_multiple_q_ismh_ax1_v.plot(y2_v[160:180], elements.load('ISMHexp')[160:180, 128],249 linewidth=3, label=str(q_v[count]))250 fig_test2_multiple_q_ismh_ax2_v.plot(y2_v,251 np.log1p(np.fft.fftshift(np.abs(elements.load('FTISMHexp') ** 2)))[:, 128],252 linewidth=3, label=str(q_v[count]))253 error_delta_g_v = np.abs(elements.load_g('Mask1', 'deltagM')[0, :, 128])254 fig_test2_error_delta_g_ax_v.plot(y2_v, error_delta_g_v, linewidth=3, label=str(q_v[count]))255 mean_test_2_v.append(statistics.mean(elements.load_g('Mask1', 'deltagM')[0, :, 128]))256 stand_dev_test_2_v.append(statistics.stdev(elements.load_g('Mask1', 'deltagM')[0, :, 128]))257 count += 1258fig_test2_multiple_q_ax1_v.set_ylim(-np.pi, np.pi)259fig_test2_multiple_q_ax1_v.legend()260fig_test2_multiple_q_ax1_v.set_title('Phase corrected')261fig_test2_multiple_q_ax2_v.set_title('Vertical component of Îg')262fig_test2_multiple_q_ax2_v.set_ylim(-0.01, 0.01)263fig_test2_multiple_q_ismh_ax1_v.set_title('I_SMH')264fig_test2_multiple_q_ismh_ax2_v.set_title('Fourier Transform of I_SMH')265fig_test2_multiple_q_ismh_ax2_v.legend()266fig_test2_error_delta_g_ax_v.set_ylim(0, 0.0025)267fig_test2_error_delta_g_ax_v.legend()268fig_test2_error_delta_g_ax_v.set_title('Error of the vertical component of Îg ')269fig_test2_multiple_q_v.savefig(270 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_v_test_results.png',271 dpi=300, bbox_inches='tight')272fig_test2_multiple_q_ismh_v.savefig(273 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_v_test_cases.png',274 dpi=300, bbox_inches='tight')275fig_test2_error_delta_g_v.savefig(276 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_2_v_test_error.png',277 dpi=300, bbox_inches='tight')278plt.show()279print('Mean test 2 = ', mean_test_2_v)280print('StDev test 2 = ', stand_dev_test_2_v)281# #######################################282# Test #3 in TestPlan document283# #######################################284data_test_3 = data.SMGData()285# STEM Moire hologram with a unique periodicity of 4 pixels along horizontal axis on half image and a periodicity of286# 4.5 pixel along the same axis on the second half of the image (easy case). This leads to o a 'delta g' of287# 1/4-1/4.5 = 0.0277778.288x3a = np.linspace(0, 127, 128)289x3b = np.linspace(128, 255, 128)290y3 = np.linspace(0, 255, 256)291mx3a, my3a = np.meshgrid(x3a, y3)292mx3b, my3b = np.meshgrid(x3b, y3)293ismh3a = np.sin(mx3a * 2 * np.pi / 4)294ismh3b = np.sin(mx3b * 2 * np.pi / 4.5)295ismh3 = np.concatenate((ismh3a, ismh3b), axis=1)296ft_ismh3 = np.fft.fft2(ismh3)297# Store data in datastructure298data_test_3.store('ISMHexp', ismh3)299data_test_3.store('FTISMHexp', ft_ismh3)300# Create branch for mask301data_test_3.create_branch('Mask1')302# Circle of radius R centered around coordinate (192, 128)303r3 = 20304center3 = (192, 128)305circle3 = center3, r3306# Store mask properties into datastructure307data_test_3.store_g('Mask1', 'Mask', circle3)308# Entering gpa309gpa.gpa('Mask1', data_test_3)310# Display data311# Input/Output data - Phase is supposed to be constant and equal to 0, anything different from 0 represents the error.312fig_test3 = plt.figure(figsize=(13, 9))313fig_test3_ax1 = fig_test3.add_subplot(2, 3, 1)314fig_test3_ax2 = fig_test3.add_subplot(2, 3, 4)315fig_test3_ax3 = fig_test3.add_subplot(2, 3, 2)316fig_test3_ax4 = fig_test3.add_subplot(2, 3, 5)317fig_test3_ax5 = fig_test3.add_subplot(2, 3, 3)318fig_test3_ax6 = fig_test3.add_subplot(2, 3, 6)319fig_test3_ax1.imshow(ismh3, cmap='gray')320fig_test3_ax2.imshow(np.log1p(np.fft.fftshift(np.abs(ft_ismh3 ** 2))), cmap='gray')321fig_test3_ax3.imshow(data_test_3.load_g('Mask1', 'phaseraw'), cmap='gray', vmin=-np.pi, vmax=np.pi)322fig_test3_ax4.imshow(data_test_3.load_g('Mask1', 'phasegM'), cmap='gray', vmin=-np.pi, vmax=np.pi)323fig_test3_ax5.imshow(data_test_3.load_g('Mask1', 'deltagM')[0], cmap='gray', vmin=-1, vmax=1)324fig_test3_ax6.imshow(data_test_3.load_g('Mask1', 'deltagM')[1], cmap='gray', vmin=-1, vmax=1)325fig_test3_ax1.set_title('I_SMH')326fig_test3_ax2.set_title('Fourier Transform of I_SMH')327fig_test3_ax3.set_title('Raw Phase')328fig_test3_ax4.set_title('Phase corrected')329fig_test3_ax5.set_title('Vertical component of Îg')330fig_test3_ax6.set_title('Horizontal component of Îg')331fig_test3.savefig(332 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_3_explanation.png',333 dpi=300, bbox_inches='tight')334# Input/Output data in 1D335fig_test3_1d = plt.figure(figsize=(13, 9))336fig_test3_1d_ax1 = fig_test3_1d.add_subplot(2, 3, 1)337fig_test3_1d_ax2 = fig_test3_1d.add_subplot(2, 3, 4)338fig_test3_1d_ax3 = fig_test3_1d.add_subplot(2, 3, 2)339fig_test3_1d_ax4 = fig_test3_1d.add_subplot(2, 3, 5)340fig_test3_1d_ax5 = fig_test3_1d.add_subplot(2, 3, 3)341fig_test3_1d_ax6 = fig_test3_1d.add_subplot(2, 3, 6)342fig_test3_1d_ax1.plot(x2[50:206], ismh3[128, 50:206])343fig_test3_1d_ax2.plot(x2, np.log1p(np.fft.fftshift(np.abs(ft_ismh3 ** 2)))[128, :])344fig_test3_1d_ax3.plot(x2, data_test_3.load_g('Mask1', 'phaseraw')[128, :])345fig_test3_1d_ax3.set_ylim(-np.pi, np.pi)346fig_test3_1d_ax4.plot(x2, data_test_3.load_g('Mask1', 'phasegM')[128, :])347fig_test3_1d_ax4.set_ylim(-np.pi, np.pi)348fig_test3_1d_ax5.plot(x2, data_test_3.load_g('Mask1', 'deltagM')[0, 128, :])349fig_test3_1d_ax5.set_ylim(-0.1, 0.1)350fig_test3_1d_ax6.plot(x2, data_test_3.load_g('Mask1', 'deltagM')[1, 128, :])351fig_test3_1d_ax6.set_ylim(-0.1, 0.1)352fig_test3_1d_ax1.set_title('I_SMH')353fig_test3_1d_ax2.set_title('Fourier Transform of I_SMH')354fig_test3_1d_ax3.set_title('Raw Phase')355fig_test3_1d_ax4.set_title('Phase corrected')356fig_test3_1d_ax5.set_title('Vertical component of Îg')357fig_test3_1d_ax6.set_title('Horizontal component of Îg')358fig_test3_1d.savefig(359 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_3_explanation_1D.png',360 dpi=300, bbox_inches='tight')361plt.show()362# -------------------- Test #3 Improvement ---------------363# Different strain level: dg364dg = [1/4 - 1/3, 1/4 - 1/3.8, 1/4 - 1/3.9, 1/4 - 1/4, 1/4 - 1/4.1, 1/4 - 1/4.2, 1/4 - 1/5]365# Different strain periodicity366dq = [3, 3.8, 3.9, 4, 4.1, 4.2, 5]367data3 = []368for strain in dq:369 ismhb = np.sin(mx3b * 2 * np.pi / strain)370 ismh = np.concatenate((ismh3a, ismhb), axis=1)371 ft_ismh = np.fft.fft2(ismh)372 circle = (128 + round(256 / 4), 128), r3373 print(circle)374 data_i = data.SMGData()375 data_i.store('ISMHexp', ismh)376 data_i.store('FTISMHexp', ft_ismh)377 data_i.create_branch('Mask1')378 data_i.store_g('Mask1', 'Mask', circle)379 gpa.gpa('Mask1', data_i)380 data3.append(data_i)381fig_test3_multiple_dq = plt.figure(figsize=(13, 6))382fig_test3_multiple_dq_ax1 = fig_test3_multiple_dq.add_subplot(1, 2, 1)383fig_test3_multiple_dq_ax2 = fig_test3_multiple_dq.add_subplot(1, 2, 2)384count = 0385strain_values = []386for elements in data3:387 fig_test3_multiple_dq_ax1.plot(x2[100:200], elements.load_g('Mask1', 'phasegM')[128, 100:200],388 linewidth=3, label=str(dq[count]))389 fig_test3_multiple_dq_ax2.plot(x2, elements.load_g('Mask1', 'deltagM')[1, 128, :],390 linewidth=3, label=str(dq[count]))391 strain_value = elements.load_g('Mask1', 'deltagM')[1, 128, 200]392 strain_values.append(strain_value)393 count += 1394fig_test3_multiple_dq_ax1.set_ylim(-np.pi, np.pi)395fig_test3_multiple_dq_ax1.legend()396fig_test3_multiple_dq_ax1.set_title('Raw phase')397fig_test3_multiple_dq_ax2.set_title('Horizontal component of Îg')398fig_test3_multiple_dq_ax2.set_ylim(-0.1, 0.1)399fig_test3_multiple_dq.savefig(400 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_3_test_results.png',401 dpi=300, bbox_inches='tight')402print('dg = ', dg)403print('strain = ', strain_values)404print('error = ', np.abs(np.array(dg)-np.array(strain_values)))405plt.show()406# ----------------------- Test vertical component ----------------------407data_test_3_v = data.SMGData()408# STEM Moire hologram with a unique periodicity of 4 pixels along horizontal axis on half image and a periodicity of409# 4.5 pixel along the same axis on the second half of the image (easy case). This leads to o a 'delta g' of410# 1/4-1/4.5 = 0.0277778.411y3a_v = np.linspace(0, 127, 128)412y3b_v = np.linspace(128, 255, 128)413x3_v = np.linspace(0, 255, 256)414mx3a_v, my3a_v = np.meshgrid(x3_v, y3a_v)415mx3b_v, my3b_v = np.meshgrid(x3_v, y3b_v)416ismh3a_v = np.sin(my3a_v * 2 * np.pi / 4)417ismh3b_v = np.sin(my3b_v * 2 * np.pi / 4.5)418ismh3_v = np.concatenate((ismh3a_v, ismh3b_v), axis=0)419ft_ismh3_v = np.fft.fft2(ismh3_v)420# Store data in datastructure421data_test_3_v.store('ISMHexp', ismh3_v)422data_test_3_v.store('FTISMHexp', ft_ismh3_v)423# Create branch for mask424data_test_3_v.create_branch('Mask1')425# Circle of radius R centered around coordinate (192, 128)426r3_v = 20427center3_v = (128, 192)428circle3_v = center3_v, r3_v429# Store mask properties into datastructure430data_test_3_v.store_g('Mask1', 'Mask', circle3_v)431# Entering gpa432gpa.gpa('Mask1', data_test_3_v)433# Display data434# Input/Output data - Phase is supposed to be constant and equal to 0, anything different from 0 represents the error.435fig_test3_v = plt.figure(figsize=(13, 9))436fig_test3_ax1_v = fig_test3_v.add_subplot(2, 3, 1)437fig_test3_ax2_v = fig_test3_v.add_subplot(2, 3, 4)438fig_test3_ax3_v = fig_test3_v.add_subplot(2, 3, 2)439fig_test3_ax4_v = fig_test3_v.add_subplot(2, 3, 5)440fig_test3_ax5_v = fig_test3_v.add_subplot(2, 3, 3)441fig_test3_ax6_v = fig_test3_v.add_subplot(2, 3, 6)442fig_test3_ax1_v.imshow(ismh3_v, cmap='gray')443fig_test3_ax2_v.imshow(np.log1p(np.fft.fftshift(np.abs(ft_ismh3_v ** 2))), cmap='gray')444fig_test3_ax3_v.imshow(data_test_3_v.load_g('Mask1', 'phaseraw'), cmap='gray', vmin=-np.pi, vmax=np.pi)445fig_test3_ax4_v.imshow(data_test_3_v.load_g('Mask1', 'phasegM'), cmap='gray', vmin=-np.pi, vmax=np.pi)446fig_test3_ax5_v.imshow(data_test_3_v.load_g('Mask1', 'deltagM')[0], cmap='gray', vmin=-1, vmax=1)447fig_test3_ax6_v.imshow(data_test_3_v.load_g('Mask1', 'deltagM')[1], cmap='gray', vmin=-1, vmax=1)448fig_test3_ax1_v.set_title('I_SMH')449fig_test3_ax2_v.set_title('Fourier Transform of I_SMH')450fig_test3_ax3_v.set_title('Raw Phase')451fig_test3_ax4_v.set_title('Phase corrected')452fig_test3_ax5_v.set_title('Vertical component of Îg')453fig_test3_ax6_v.set_title('Horizontal component of Îg')454fig_test3_v.savefig(455 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_3_v_explanation.png',456 dpi=300, bbox_inches='tight')457# Input/Output data in 1D458fig_test3_1d_v = plt.figure(figsize=(13, 9))459fig_test3_1d_ax1_v = fig_test3_1d_v.add_subplot(2, 3, 1)460fig_test3_1d_ax2_v = fig_test3_1d_v.add_subplot(2, 3, 4)461fig_test3_1d_ax3_v = fig_test3_1d_v.add_subplot(2, 3, 2)462fig_test3_1d_ax4_v = fig_test3_1d_v.add_subplot(2, 3, 5)463fig_test3_1d_ax5_v = fig_test3_1d_v.add_subplot(2, 3, 3)464fig_test3_1d_ax6_v = fig_test3_1d_v.add_subplot(2, 3, 6)465fig_test3_1d_ax1_v.plot(x2[50:206], ismh3_v[50:206, 128])466fig_test3_1d_ax2_v.plot(x2, np.log1p(np.fft.fftshift(np.abs(ft_ismh3_v ** 2)))[:, 128])467fig_test3_1d_ax3_v.plot(x2, data_test_3_v.load_g('Mask1', 'phaseraw')[:, 128])468fig_test3_1d_ax3_v.set_ylim(-np.pi, np.pi)469fig_test3_1d_ax4_v.plot(x2, data_test_3_v.load_g('Mask1', 'phasegM')[:, 128])470fig_test3_1d_ax4_v.set_ylim(-np.pi, np.pi)471fig_test3_1d_ax5_v.plot(x2, data_test_3_v.load_g('Mask1', 'deltagM')[0, :, 128])472fig_test3_1d_ax5_v.set_ylim(-0.1, 0.1)473fig_test3_1d_ax6_v.plot(x2, data_test_3_v.load_g('Mask1', 'deltagM')[1, :, 128])474fig_test3_1d_ax6_v.set_ylim(-0.1, 0.1)475fig_test3_1d_ax1_v.set_title('I_SMH')476fig_test3_1d_ax2_v.set_title('Fourier Transform of I_SMH')477fig_test3_1d_ax3_v.set_title('Raw Phase')478fig_test3_1d_ax4_v.set_title('Phase corrected')479fig_test3_1d_ax5_v.set_title('Vertical component of Îg')480fig_test3_1d_ax6_v.set_title('Horizontal component of Îg')481fig_test3_1d_v.savefig(482 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_3_v_explanation_1D.png',483 dpi=300, bbox_inches='tight')484# -------------------- Test #3 Improvement ---------------485# Different strain level: dg486dg = [1/4 - 1/3, 1/4 - 1/3.8, 1/4 - 1/3.9, 1/4 - 1/4, 1/4 - 1/4.1, 1/4 - 1/4.2, 1/4 - 1/5]487# Different strain periodicity488dq = [3, 3.8, 3.9, 4, 4.1, 4.2, 5]489data3 = []490for strain in dq:491 ismhb = np.sin(mx3b * 2 * np.pi / strain)492 ismh = np.concatenate((ismh3a, ismhb), axis=1)493 ft_ismh = np.fft.fft2(ismh)494 circle = (128 + round(256 / 4), 128), r3495 print(circle)496 data_i = data.SMGData()497 data_i.store('ISMHexp', ismh)498 data_i.store('FTISMHexp', ft_ismh)499 data_i.create_branch('Mask1')500 data_i.store_g('Mask1', 'Mask', circle)501 gpa.gpa('Mask1', data_i)502 data3.append(data_i)503fig_test3_multiple_dq = plt.figure(figsize=(13, 6))504fig_test3_multiple_dq_ax1 = fig_test3_multiple_dq.add_subplot(1, 2, 1)505fig_test3_multiple_dq_ax2 = fig_test3_multiple_dq.add_subplot(1, 2, 2)506count = 0507strain_values = []508for elements in data3:509 fig_test3_multiple_dq_ax1.plot(x2[100:200], elements.load_g('Mask1', 'phasegM')[128, 100:200],510 linewidth=3, label=str(dq[count]))511 fig_test3_multiple_dq_ax2.plot(x2, elements.load_g('Mask1', 'deltagM')[1, 128, :],512 linewidth=3, label=str(dq[count]))513 strain_value = elements.load_g('Mask1', 'deltagM')[1, 128, 200]514 strain_values.append(strain_value)515 count += 1516fig_test3_multiple_dq_ax1.set_ylim(-np.pi, np.pi)517fig_test3_multiple_dq_ax1.legend()518fig_test3_multiple_dq_ax1.set_title('Raw phase')519fig_test3_multiple_dq_ax2.set_title('Horizontal component of Îg')520fig_test3_multiple_dq_ax2.set_ylim(-0.1, 0.1)521fig_test3_multiple_dq.savefig(522 '/media/alex/Work/PhD/Course/CAS 741/project/STEM_Moire_GPA/Doc/TestReport/Figures/Test_3_test_results.png',523 dpi=300, bbox_inches='tight')524print('dg = ', dg)525print('strain = ', strain_values)526print('error = ', np.abs(np.array(dg)-np.array(strain_values)))527plt.show()528# #######################################529# Test #4 in TestPlan document530# #######################################531data_test_4 = data.SMGData()532# STEM Moire hologram with a unique periodicity of 4 pixels along horizontal axis on half image and a periodicity of533# 4.5 pixel along the same axis on the second half of the image (easy case). This leads to o a 'delta g' of534# 1/4-1/4.5 = 0.0277778.535x4a = np.linspace(0, 127, 128)536x4b = np.linspace(128, 255, 128)537y4 = np.linspace(0, 255, 256)538mx4a, my4a = np.meshgrid(x4a, y4)539mx4b, my4b = np.meshgrid(x4b, y4)540ismh4a = np.sin(mx4a * 2 * np.pi / 4)541ismh4b = np.sin(mx4b * 2 * np.pi / 4.5)542ismh4 = np.concatenate((ismh4a, ismh4b), axis=1)543ft_ismh4 = np.fft.fft2(ismh4)544# Store data in datastructure545data_test_4.store('ISMHexp', ismh4)546data_test_4.store('FTISMHexp', ft_ismh4)547# Mask parameter548r4 = [1, 2, 4, 8, 16, 32, 64, 128, 256]549center4 = (192, 128)550# Create the amount of branches corresponding the the radius tested and store the mask properties551for radius in r4:552 data_test_4.create_branch(str(radius))553 circle4 = center4, radius554 data_test_4.store_g(str(radius), 'Mask', circle4)555# Looping on the various radius into gpa556for radius in r4:557 gpa.gpa(str(radius), data_test_4)558count = 1559fig_test4 = plt.figure()560fig_test4_1d = plt.figure()561fig_test4_deltag_1d = plt.figure()562N_sublpot = math.ceil(math.sqrt(len(r4)))563print(math.ceil(math.sqrt(len(r4))))564for element in r4:565 fig_test4.add_subplot(N_sublpot, N_sublpot, count).imshow(data_test_4.load_g(566 str(element), 'phasegM'), cmap='gray', vmin=-np.pi, vmax=np.pi)567 fig_ax = fig_test4_1d.add_subplot(N_sublpot, N_sublpot, count)568 fig_ax.plot(x2, data_test_4.load_g(str(element), 'phasegM')[128, :])569 fig_ax.set_ylim(-np.pi, np.pi)570 fig_ax_g = fig_test4_deltag_1d.add_subplot(N_sublpot, N_sublpot, count)571 fig_ax_g.plot(x2, data_test_4.load_g(572 str(element), 'deltagM')[1, 128, :])573 fig_ax_g.set_ylim(-0.1, 0.1)574 count += 1...`

test_unittest.py

Source:test_unittest.py

`1#!/usr/bin/python2#3# Copyright 2008 Google Inc. All Rights Reserved.4"""Tests for test."""5import unittest, sys, os6import common7from autotest_lib.cli import cli_mock, topic_common, test8from autotest_lib.client.common_lib import control_data9CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT10SERVER = control_data.CONTROL_TYPE_NAMES.SERVER11class test_list_unittest(cli_mock.cli_unittest):12 values = [{u'description': u'unknown',13 u'test_type': CLIENT,14 u'test_class': u'Canned Test Sets',15 u'path': u'client/tests/test0/control',16 u'synch_type': u'Asynchronous',17 u'id': 138,18 u'name': u'test0',19 u'experimental': False},20 {u'description': u'unknown',21 u'test_type': SERVER,22 u'test_class': u'Kernel',23 u'path': u'server/tests/test1/control',24 u'synch_type': u'Asynchronous',25 u'id': 139,26 u'name': u'test1',27 u'experimental': False},28 {u'description': u'unknown',29 u'test_type': CLIENT,30 u'test_class': u'Canned Test Sets',31 u'path': u'client/tests/test2/control.readprofile',32 u'synch_type': u'Asynchronous',33 u'id': 140,34 u'name': u'test2',35 u'experimental': False},36 {u'description': u'unknown',37 u'test_type': SERVER,38 u'test_class': u'Canned Test Sets',39 u'path': u'server/tests/test3/control',40 u'synch_type': u'Asynchronous',41 u'id': 142,42 u'name': u'test3',43 u'experimental': False},44 {u'description': u'Random stuff to check that things are ok',45 u'test_type': CLIENT,46 u'test_class': u'Hardware',47 u'path': u'client/tests/test4/control.export',48 u'synch_type': u'Asynchronous',49 u'id': 143,50 u'name': u'test4',51 u'experimental': True}]52 def test_test_list_tests_default(self):53 self.run_cmd(argv=['atest', 'test', 'list'],54 rpcs=[('get_tests', {'experimental': False},55 True, self.values)],56 out_words_ok=['test0', 'test1', 'test2',57 'test3', 'test4'],58 out_words_no=['Random', 'control.export'])59 def test_test_list_tests_all(self):60 self.run_cmd(argv=['atest', 'test', 'list', '--all'],61 rpcs=[('get_tests', {},62 True, self.values)],63 out_words_ok=['test0', 'test1', 'test2',64 'test3', 'test4'],65 out_words_no=['Random', 'control.export'])66 def test_test_list_tests_exp(self):67 self.run_cmd(argv=['atest', 'test', 'list', '--experimental'],68 rpcs=[('get_tests', {'experimental': True},69 True,70 [{u'description': u'Random stuff',71 u'test_type': CLIENT,72 u'test_class': u'Hardware',73 u'path': u'client/tests/test4/control.export',74 u'synch_type': u'Asynchronous',75 u'id': 143,76 u'name': u'test4',77 u'experimental': True}])],78 out_words_ok=['test4'],79 out_words_no=['Random', 'control.export'])80 def test_test_list_tests_select_one(self):81 filtered = [val for val in self.values if val['name'] in ['test3']]82 self.run_cmd(argv=['atest', 'test', 'list', 'test3'],83 rpcs=[('get_tests', {'name__in': ['test3'],84 'experimental': False},85 True, filtered)],86 out_words_ok=['test3'],87 out_words_no=['test0', 'test1', 'test2', 'test4',88 'unknown'])89 def test_test_list_tests_select_two(self):90 filtered = [val for val in self.values91 if val['name'] in ['test3', 'test1']]92 self.run_cmd(argv=['atest', 'test', 'list', 'test3,test1'],93 rpcs=[('get_tests', {'name__in': ['test1', 'test3'],94 'experimental': False},95 True, filtered)],96 out_words_ok=['test3', 'test1', SERVER],97 out_words_no=['test0', 'test2', 'test4',98 'unknown', CLIENT])99 def test_test_list_tests_select_two_space(self):100 filtered = [val for val in self.values101 if val['name'] in ['test3', 'test1']]102 self.run_cmd(argv=['atest', 'test', 'list', 'test3', 'test1'],103 rpcs=[('get_tests', {'name__in': ['test1', 'test3'],104 'experimental': False},105 True, filtered)],106 out_words_ok=['test3', 'test1', SERVER],107 out_words_no=['test0', 'test2', 'test4',108 'unknown', CLIENT])109 def test_test_list_tests_all_verbose(self):110 self.run_cmd(argv=['atest', 'test', 'list', '-v'],111 rpcs=[('get_tests', {'experimental': False},112 True, self.values)],113 out_words_ok=['test0', 'test1', 'test2',114 'test3', 'test4', 'client/tests',115 'server/tests'],116 out_words_no=['Random'])117 def test_test_list_tests_all_desc(self):118 self.run_cmd(argv=['atest', 'test', 'list', '-d'],119 rpcs=[('get_tests', {'experimental': False},120 True, self.values)],121 out_words_ok=['test0', 'test1', 'test2',122 'test3', 'test4', 'unknown', 'Random'],123 out_words_no=['client/tests', 'server/tests'])124 def test_test_list_tests_all_desc_verbose(self):125 self.run_cmd(argv=['atest', 'test', 'list', '-d', '-v'],126 rpcs=[('get_tests', {'experimental': False},127 True, self.values)],128 out_words_ok=['test0', 'test1', 'test2',129 'test3', 'test4', 'client/tests',130 'server/tests', 'unknown', 'Random' ])131if __name__ == '__main__':...`

uniterrorcharsets.py

Source:uniterrorcharsets.py

`1#!/usr/bin/env python2import sys3import bots.botslib as botslib4import bots.botsglobal as botsglobal5import bots.botsinit as botsinit6'''7no plugin needed.8run in commandline.9should give no errors.10utf-16 etc are reported.11'''12def testraise(expect,msg2,*args,**kwargs):13 try:14 raise botslib.BotsError(msg2,*args,**kwargs)15 except Exception, msg:16 if not isinstance(msg,unicode):17 msg = unicode(msg)18 #~ print 'not unicode',type(msg),expect19 #~ print 'Error xxx\n',msg20 if expect:21 if unicode(expect) != msg.strip():22 print expect,'(expected)'23 print msg,'(received)'24 txt = botslib.txtexc()25 if not isinstance(txt,unicode):26 print 'Error txt\n',txt27 28# .decode(): bytes->unicode29# .encode(): unicode -> bytes30def testrun():31 print '\n'32 #normal, valid handling33 testraise('','',{'test1':'test1','test2':'test2','test3':'test3'})34 testraise('0test','0test',{'test1':'test1','test2':'test2','test3':'test3'})35 testraise('0test test1 test2','0test %(test1)s %(test2)s %(test4)s',{'test1':'test1','test2':'test2','test3':'test3'})36 testraise('1test test1 test2 test3','1test %(test1)s %(test2)s %(test3)s',{'test1':'test1','test2':'test2','test3':'test3'})37 testraise(u'2test test1 test2 test3',u'2test %(test1)s %(test2)s %(test3)s',{u'test1':u'test1',u'test2':u'test2',u'test3':u'test3'})38 #different inputs in BotsError39 testraise(u'3test','3test')40 testraise(u'4test test1 test2',u'4test %(test1)s %(test2)s %(test3)s',{u'test1':u'test1',u'test2':u'test2'})41 testraise(u'5test test1 test2',u'5test %(test1)s %(test2)s %(test3)s',test1=u'test1',test2=u'test2')42 testraise(u'6test',u'6test %(test1)s %(test2)s %(test3)s',u'test1')43 testraise(u"7test [u'test1', u'test2']",u'7test %(test1)s %(test2)s %(test3)s',test1=[u'test1',u'test2'])44 testraise(u"8test {u'test1': u'test1', u'test2': u'test2'}",u'8test %(test1)s %(test2)s %(test3)s',test1={u'test1':u'test1',u'test2':u'test2'})45 testraise(u"9test [<module 'bots.botslib' from '/home/hje/Bots/botsdev/bots/botslib.pyc'>, <module 'bots.botslib' from '/home/hje/Bots/botsdev/bots/botslib.pyc'>]",46 u'9test %(test1)s %(test2)s %(test3)s',test1=[botslib,botslib])47 #different charsets in BotsError48 testraise(u'12test test1 test2 test3',u'12test %(test1)s %(test2)s %(test3)s',{u'test1':u'test1',u'test2':u'test2',u'test3':u'test3'})49 testraise(u'13test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 test2\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 test3\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202',50 u'13test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 %(test1)s %(test2)s %(test3)s',51 {u'test1':u'test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202',u'test2':u'test2\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202',u'test3':u'test3\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202'})52 testraise(u'14test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202',53 u'14test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 %(test1)s'.encode('utf_8'),54 {u'test1':u'test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202'.encode('utf_8')})55 testraise(u'15test test1',56 u'15test %(test1)s',57 {u'test1':u'test1'.encode('utf_16')})58 testraise(u'16test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202',59 u'16test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 %(test1)s',60 {u'test1':u'test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202'.encode('utf_16')})61 testraise(u'17test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202',62 u'17test\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202 %(test1)s',63 {u'test1':u'test1\u00E9\u00EB\u00FA\u00FB\u00FC\u0103\u0178\u01A1\u0202'.encode('utf_32')})64 testraise(u'18test\u00E9\u00EB\u00FA\u00FB\u00FC test1\u00E9\u00EB\u00FA\u00FB\u00FC',65 u'18test\u00E9\u00EB\u00FA\u00FB\u00FC %(test1)s',66 {u'test1':u'test1\u00E9\u00EB\u00FA\u00FB\u00FC'.encode('latin_1')})67 testraise(u'19test test1',68 u'19test %(test1)s',69 {u'test1':u'test1'.encode('cp500')})70 testraise(u'20test test1',71 u'20test %(test1)s',72 {u'test1':u'test1'.encode('euc_jp')})73 #make utf-8 unicode string,many chars74 l = []75 for i in xrange(0,pow(256,2)):76 l.append(unichr(i))77 s = u''.join(l)78 print type(s)79 testraise(u'',s)80 #~ print type(s)81 s2 = s.encode('utf-8')82 print type(s2)83 testraise(u'',s2)84 85 #make iso-8859-1 string,many chars86 l = []87 for i in range(0,256):88 l.append(chr(i))89 s = ''.join(l)90 print type(s)91 #~ print s92 testraise(u'',s)93 s2 = s.decode('latin_1')94 print type(s2)95 testraise(u'',s2)96if __name__ == '__main__':97 botsinit.generalinit('config')98 botsinit.initbotscharsets()99 botsglobal.logger = botsinit.initenginelogging('engine')100 botsglobal.ini.set('settings','debug','False')101 testrun()102 botsglobal.ini.set('settings','debug','True')103 testrun()...`

testsealable.py

Source:testsealable.py

`...116 m.test1.test2.test3.test4.boom117 self.assertIn("mock_name.test1.test2.test3.test4.boom", str(cm.exception))118 def test_call_chain_is_maintained(self):119 m = mock.Mock()120 m.test1().test2.test3().test4121 mock.seal(m)122 with self.assertRaises(AttributeError) as cm:123 m.test1().test2.test3().test4()124 self.assertIn("mock.test1().test2.test3().test4", str(cm.exception))125if __name__ == "__main__":...`

## Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.