Best Python code snippet using lisa_python
__init__.py
Source:__init__.py  
1from __future__ import print_function2from pylab import *3import functools4from matplotlib.pyplot import *5import _dict_it6import _dict_find7import _dict_update_slice8import _set_it9import _set_insert10import _set_find11import _set_find_local12import _set_create13import _set_insert_sort14import _dict_insert_sort15import _set_insert_erase16import _dict_insert_erase17import _set_insert_rank18import _set_insert_min_gap19import _set_erase_slice20import _set_insert_overlapping_intervals21    22_run_create = False23_run_insert_overlapping_intervals = False24_run_it = False25_run_insert_sort = False26_run_insert_rank = False27_run_insert_erase = True28_run_find = False29_run_erase_slice = False30_run_update_slice = False31_run_find_local = False32_run_insert_min_gap = False33class _Recorder(object):34    def __init__(self):35        self._x_vals = []36        self._results = dict([])37    def add_results(self, x_val, res):38        print(res)39        self._x_vals.append(x_val)40        for n in list(res.keys()):41            self._results.setdefault(n, []).append(res[n])42    def maxes_res(self):43        maxes = [(n, max(res)) for n, res in self._results.items()]44        maxes.sort(key = lambda nm: nm[1])45        46        return maxes, self._results47        48def _single_malt(fn, x_range, num_its, algs, title, f_name):49    fig = figure()50    ax = subplot(111)51    xlabel('# Items')52    ylabel('Time (sec.)')53    ticklabel_format(style = 'sci', axis='y', scilimits=(0,0))        54    55    r = _Recorder()56    for x in x_range:57        print('running', f_name, x)58        r.add_results(x, fn(algs, x, num_its))59    maxes, res = r.maxes_res()60    for n in [nm[0] for nm in maxes]:61        ax.plot(x_range, res[n], label = n)62        63    box = ax.get_position()    64    ax.set_position([box.x0, box.y0 + box.height * 0.3, box.width, box.height * 0.72])65    ax.legend(66        [n for (n, m) in maxes], 67        loc = 'upper center', 68        bbox_to_anchor = (0.5, -0.1),69        ncol = 2 if len(maxes) > 5 else 1)70    text(0.5, 1.08, title,71         horizontalalignment='center',72         fontsize = 13,73         transform = ax.transAxes)        74    # subtitle(title)        75    savefig(f_name)    76    77_banyans = [78    'banyan_red_black_tree', 79    'banyan_splay_tree', 80    'banyan_sorted_list',81    'banyan_red_black_tree_gen', 82    'banyan_splay_tree_gen', 83    'banyan_sorted_list_gen']    84if __name__ == '__main__':85    #num_its = 186    num_its = 3087    #base = 1 88    base = 5089    90    if _run_find_local:91        for type_, type_str in [(int, 'Int'), (str, 'Str')]:92            _single_malt(93                functools.partial(_set_find_local.run_tests, type_ = type_), 94                [base * i for i in range(1, 10)], 95                500 * num_its, 96                _banyans + ['blist', 'btrees', 'set'],97                'All Items Repeated Find Time As A Function Of # Items',98                type_str + 'SetFindLocalAll.png')99            _single_malt(100                functools.partial(_set_find_local.run_tests, type_ = type_), 101                [base * i for i in range(1, 10)], 102                500 * num_its, 103                _banyans + ['btrees', 'set'],104                'All Items Repeated Find Time As A Function Of # Items',105                type_str + 'SetFindLocalAllNoBList.png')106                107            _single_malt(108                functools.partial(_set_find_local.run_tests, type_ = type_), 109                [base * i for i in range(1, 10)], 110                500 * num_its, 111                ['banyan_red_black_tree', 'banyan_splay_tree', 'set', 'btrees'],112                'All Items Repeated Find Time As A Function Of # Items',113                type_str + 'SetFindLocalCompetitive.png')114    if _run_insert_overlapping_intervals:115        _single_malt(116            _set_insert_overlapping_intervals.run_tests, 117            [base * i for i in range(1, 10)], 118            50 * num_its, 119            ['banyan_red_black_tree', 'bx'],120            'All Items Insert + Last Interval Overlaps As A Function Of # Items',121            'IntSetInsertOverlappingCompetitive.png')122        _single_malt(123            _set_insert_overlapping_intervals.run_tests, 124            [base * i for i in range(1, 10)], 125            50 * num_its, 126            ['banyan_red_black_tree', 'banyan_red_black_tree_float', 'banyan_red_black_tree_gen', 'bx'],127            'All Items Insert + Last Interval Overlaps As A Function Of # Items',128            'IntSetInsertOverlappingAll.png')129    if _run_update_slice:130        _single_malt(131            _dict_update_slice.run_tests, 132            [base * i for i in range(1, 10)], 133            50 * num_its, 134            _banyans + ['bintrees', 'btrees', 'blist', 'dict'],135            'Update Fixed-Size Slice As A Function Of # Items',136            'IntDictUpdateSliceAll.png')    137        _single_malt(138            _dict_update_slice.run_tests, 139            [base * i for i in range(1, 10)], 140            50 * num_its, 141            _banyans + ['btrees', 'dict'],142            'Update Fixed-Size Slice As A Function Of # Items',143            'IntDictUpdateSliceAllNoBListBintrees.png')    144        _single_malt(145            _dict_update_slice.run_tests, 146            [base * i for i in range(1, 10)], 147            50 * num_its, 148            ['banyan_red_black_tree', 'btrees', 'dict'],149            'Update Fixed-Size Slice As A Function Of # Items',150            'IntDictUpdateSliceCompetitive.png')    151    if _run_erase_slice:152        _single_malt(153            _set_erase_slice.run_tests, 154            [base * i for i in range(1, 10)], 155            50 * num_its, 156            _banyans + ['bintrees', 'set'],157            'Erase Fixed-Size Slice As A Function Of # Items',158            'IntSetEraseSliceAll.png')    159    160        _single_malt(161            _set_erase_slice.run_tests, 162            [base * i for i in range(1, 10)], 163            50 * num_its, 164            ['banyan_red_black_tree', 'bintrees', 'set'],165            'Erase Fixed-Size Slice As A Function Of # Items',166            'IntSetEraseSliceCompetitive.png')    167    if _run_find:168        for type_, type_str in [(int, 'Int'), (str, 'Str')]:169            _single_malt(170                functools.partial(_set_find.run_tests, type_ = type_), 171                [base * i for i in range(1, 10)], 172                200 * num_its, 173                [174                    'banyan_red_black_tree', 175                    'banyan_red_black_tree_rank_updator', 176                    'btrees', 177                    'set'],178                'All Items Find Time As A Function Of # Items',179                type_str + 'SetFindCompetitiveWithRankUpdator.png')    180            _single_malt(181                functools.partial(_dict_find.run_tests, type_ = type_), 182                [base * i for i in range(1, 10)], 183                50 * num_its, 184                _banyans + ['blist', 'btrees', 'dict'],185                'All Items Find Time As A Function Of # Items',186                type_str + 'DictFindAll.png')    187        188            _single_malt(189                functools.partial(_dict_find.run_tests, type_ = type_), 190                [base * i for i in range(1, 10)], 191                200 * num_its, 192                _banyans + ['btrees', 'dict'],193                'All Items Find Time As A Function Of # Items',194                type_str + 'DictFindAllNoBList.png')    195            _single_malt(196                functools.partial(_dict_find.run_tests, type_ = type_), 197                [base * i for i in range(1, 10)], 198                200 * num_its, 199                ['banyan_red_black_tree', 'btrees', 'dict'],200                'All Items Find Time As A Function Of # Items',201                type_str + 'DictFindCompetitive.png')    202            _single_malt(203                functools.partial(_set_find.run_tests, type_ = type_), 204                [base * i for i in range(1, 10)], 205                20 * num_its, 206                _banyans + ['blist', 'btrees', 'set'],207                'All Items Find Time As A Function Of # Items',208                type_str + 'SetFindAll.png')209            _single_malt(210                functools.partial(_set_find.run_tests, type_ = type_), 211                [base * i for i in range(1, 10)], 212                200 * num_its, 213                _banyans + ['btrees', 'set'],214                'All Items Find Time As A Function Of # Items',215                type_str + 'SetFindAllNoBList.png')216                217            _single_malt(218                functools.partial(_set_find.run_tests, type_ = type_), 219                [base * i for i in range(1, 10)], 220                200 * num_its, 221                ['banyan_red_black_tree', 'set', 'btrees'],222                'All Items Find Time As A Function Of # Items',223                type_str + 'SetFindCompetitive.png')224            _single_malt(225                functools.partial(_set_find.run_tests, type_ = type_), 226                [base * i for i in range(1, 10)], 227                300 * num_its, 228                ['banyan_red_black_tree', 'banyan_sorted_list', 'set', 'btrees'],229                'All Items Find Time As A Function Of # Items',230                type_str + 'SetFindCompetitiveWithSortedList.png')231            _single_malt(232                functools.partial(_set_find.run_tests, type_ = type_), 233                [base * i for i in range(1, 10)], 234                20 * num_its, 235                ['banyan_red_black_tree', 'banyan_splay_tree', 'set', 'btrees'],236                'All Items Find Time As A Function Of # Items',237                type_str + 'SetFindCompetitiveWithSplayTree.png')    238    if _run_it:239        _single_malt(240            _dict_it.run_tests, 241            [base * i for i in range(1, 10)], 242            5000 * num_its, 243            ['banyan_red_black_tree', 'banyan_sorted_list', 'set', 'btrees'],244            'Sorted Iteration Time As A Function Of # Items',245            'IntSetItCompetitiveWithSortedList.png')246        _single_malt(247            _set_it.run_tests, 248            [base * i for i in range(1, 10)], 249            1000 * num_its, 250            _banyans + ['bintrees', 'blist', 'btrees', 'set'],251            'Sorted Iteration Time As A Function Of # Items',252            'IntSetItAll.png')253        _single_malt(254            _set_it.run_tests, 255            [base * i for i in range(1, 10)], 256            1000 * num_its, 257            _banyans + ['btrees', 'set'],258            'Sorted Iteration Time As A Function Of # Items',259            'IntSetItAllNoBListBintrees.png')260    if _run_insert_sort:    261        for type_, type_str in [(int, 'Int'), (str, 'Str')]:262            _single_malt(263                functools.partial(_dict_insert_sort.run_tests, type_ = type_), 264                [base * i for i in range(1, 10)], 265                100 * num_its, 266                ['banyan_red_black_tree', 'dict', 'btrees'],267                'Insert + Sorted Iteration Time As A Function Of # Items',268                type_str + 'DictInsertSortCompetitive.png')269            _single_malt(270                functools.partial(_dict_insert_sort.run_tests, type_ = type_), 271                [base * i for i in range(1, 10)], 272                15 * num_its, 273                _banyans + ['bintrees', 'blist', 'btrees', 'dict'],274                'Insert + Sorted Iteration Time As A Function Of # Items',275                type_str + 'DictInsertSortAll.png')276            _single_malt(277                functools.partial(_dict_insert_sort.run_tests, type_ = type_), 278                [base * i for i in range(1, 10)], 279                100 * num_its, 280                _banyans + ['btrees', 'dict'],281                'Insert + Sorted Iteration Time As A Function Of # Items',282                type_str + 'DictInsertSortAllNoBlistBintrees.png')283            _single_malt(284                functools.partial(_dict_insert_sort.run_tests, type_ = type_), 285                [30 * base * i for i in range(1, 10)], 286                3, 287                ['banyan_red_black_tree', 'dict', 'btrees'],288                'Insert + Sorted Iteration Time As A Function Of # Items',289                type_str + 'DictInsertSortCompetitiveLarger.png')290            _single_malt(291                functools.partial(_set_insert_sort.run_tests, type_ = type_), 292                [base * i for i in range(1, 10)], 293                15 * num_its, 294                _banyans + ['bintrees', 'blist', 'btrees', 'set'],295                'Insert + Sorted Iteration Time As A Function Of # Items',296                type_str + 'SetInsertSortAll.png')297            _single_malt(298                functools.partial(_set_insert_sort.run_tests, type_ = type_), 299                [base * i for i in range(1, 10)], 300                15 * num_its, 301                _banyans + ['btrees', 'set'],302                'Insert + Sorted Iteration Time As A Function Of # Items',303                type_str + 'SetInsertSortAllNoBlistBintrees.png')304            _single_malt(305                functools.partial(_set_insert_sort.run_tests, type_ = type_), 306                [30 * base * i for i in range(1, 10)], 307                3, 308                ['banyan_red_black_tree', 'set', 'btrees'],309                'Insert + Sorted Iteration Time As A Function Of # Items',310                type_str + 'SetInsertSortCompetitiveLarger.png')311            _single_malt(312                functools.partial(_set_insert_sort.run_tests, type_ = type_), 313                [base * i for i in range(1, 10)], 314                60 * num_its, 315                ['banyan_red_black_tree', 'set', 'btrees'],316                'Insert + Sorted Iteration Time As A Function Of # Items',317                type_str + 'SetInsertSortCompetitive.png')318    if _run_insert_rank:            319        _single_malt(320            _set_insert_rank.run_tests, 321            [base * i for i in range(1, 10)], 322            30, 323            _banyans + ['banyan_red_black_tree_rank_updator', 'btrees', 'set'], 324            'Insert + Rank Time As A Function Of # Items',325            'IntSetInsertRankAllNoBListBintreesWithRankUpdator.png')326        _single_malt(327            _set_insert_rank.run_tests, 328            [base * i for i in range(1, 10)], 329            30, 330            _banyans + ['banyan_red_black_tree_rank_updator', 'bintrees', 'blist', 'btrees', 'set'], 331            'Insert + Rank Time As A Function Of # Items',332            'IntSetInsertRankAllWithRankUpdator.png')333        _single_malt(334            _set_insert_rank.run_tests, 335            [base * i for i in range(1, 10)], 336            30, 337            ['banyan_red_black_tree', 'banyan_red_black_tree_rank_updator', 'set', 'btrees'], 338            'Insert + Rank Time As A Function Of # Items',339            'IntSetInsertRankCompetitiveWithRankUpdator.png')340    if _run_insert_min_gap:            341        _single_malt(342            _set_insert_min_gap.run_tests, 343            [base * i for i in range(1, 10)], 344            20, 345            _banyans + ['banyan_red_black_tree_min_gap_updator', 'btrees', 'set'], 346            'Insert + Min-Gap Time As A Function Of # Items',347            'IntSetInsertMinGapAllNoBListBintreesWithMinGapUpdator.png')348        _single_malt(349            _set_insert_min_gap.run_tests, 350            [base * i for i in range(1, 10)], 351            20, 352            _banyans + ['banyan_red_black_tree_min_gap_updator', 'bintrees', 'blist', 'btrees', 'set'], 353            'Insert + Min-Gap Time As A Function Of # Items',354            'IntSetInsertMinGapAllWithMinGapUpdator.png')355        _single_malt(356            _set_insert_min_gap.run_tests, 357            [base * i for i in range(1, 10)], 358            20, 359            ['banyan_red_black_tree', 'banyan_red_black_tree_min_gap_updator', 'set', 'btrees'], 360            'Insert + Min-Gap Time As A Function Of # Items',361            'IntSetInsertMinGapCompetitiveWithMinGapUpdator.png')362    if _run_insert_erase:            363        for type_, type_str in [(int, 'Int'), (str, 'Str')]:364            _single_malt(365                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 366                [base * i for i in range(1, 10)], 367                30 * num_its, 368                ['banyan_red_black_tree', 'banyan_red_black_tree_rank_updator', 'dict', 'btrees'], 369                'Insert + Erase Time As A Function Of # Items',370                type_str + 'DictInsertEraseCompetitiveWithRankUpdator.png')371            _single_malt(372                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 373                [10 * base * i for i in range(1, 10)], 374                3 * num_its, 375                ['banyan_red_black_tree', 'banyan_red_black_tree_rank_updator', 'dict', 'btrees'], 376                'Insert + Erase Time As A Function Of # Items',377                type_str + 'DitInsertEraseCompetitiveWithNodeUpdatorLonger.png')378            _single_malt(379                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 380                [base * i for i in range(1, 10)], 381                100 * num_its, 382                ['banyan_red_black_tree', 'dict', 'btrees'], 383                'Insert + Erase Time As A Function Of # Items',384                type_str + 'DictInsertEraseCompetitive.png')385            _single_malt(386                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 387                [base * i for i in range(1, 10)], 388                100 * num_its, 389                ['banyan_red_black_tree', 'banyan_sorted_list', 'dict', 'btrees'], 390                'Insert + Erase Time As A Function Of # Items',391                type_str + 'DictInsertEraseCompetitiveWithSortedList.png')392            _single_malt(393                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 394                [base * i for i in range(1, 10)], 395                100 * num_its, 396                _banyans + ['bintrees', 'blist', 'btrees', 'dict'], 397                'Insert + Erase Time As A Function Of # Items',398                type_str + 'DictInsertEraseAll.png')399            _single_malt(400                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 401                [base * i for i in range(1, 10)], 402                100 * num_its, 403                _banyans + ['bintrees', 'btrees', 'dict'], 404                'Insert + Erase Time As A Function Of # Items',405                type_str + 'DictInsertEraseAllNoBList.png')406            _single_malt(407                functools.partial(_dict_insert_erase.run_tests, type_ = type_), 408                [30 * base * i for i in range(1, 10)], 409                3, 410                ['banyan_red_black_tree', 'banyan_sorted_list', 'dict', 'btrees'], 411                'Insert + Erase Time As A Function Of # Items',412                type_str + 'DictInsertEraseCompetitiveLonger.png')413            _single_malt(414                functools.partial(_set_insert_erase.run_tests, type_ = type_), 415                [base * i for i in range(1, 10)], 416                30 * num_its, 417                ['banyan_red_black_tree', 'banyan_red_black_tree_rank_updator', 'set', 'btrees'], 418                'Insert + Erase Time As A Function Of # Items',419                type_str + 'SetInsertEraseCompetitiveWithRankUpdator.png')420            _single_malt(421                functools.partial(_set_insert_erase.run_tests, type_ = type_), 422                [10 * base * i for i in range(1, 10)], 423                3 * num_its, 424                ['banyan_red_black_tree', 'banyan_red_black_tree_rank_updator', 'set', 'btrees'], 425                'Insert + Erase Time As A Function Of # Items',426                type_str + 'SetInsertEraseCompetitiveWithNodeUpdatorLonger.png')427            _single_malt(428                functools.partial(_set_insert_erase.run_tests, type_ = type_), 429                [base * i for i in range(1, 10)], 430                100 * num_its, 431                ['banyan_red_black_tree', 'set', 'btrees'], 432                'Insert + Erase Time As A Function Of # Items',433                type_str + 'SetInsertEraseCompetitive.png')434            _single_malt(435                functools.partial(_set_insert_erase.run_tests, type_ = type_), 436                [base * i for i in range(1, 10)], 437                100 * num_its, 438                ['banyan_red_black_tree', 'banyan_sorted_list', 'set', 'btrees'], 439                'Insert + Erase Time As A Function Of # Items',440                type_str + 'SetInsertEraseCompetitiveWithSortedList.png')441            _single_malt(442                functools.partial(_set_insert_erase.run_tests, type_ = type_), 443                [base * i for i in range(1, 10)], 444                100 * num_its, 445                _banyans + ['bintrees', 'blist', 'btrees', 'set'], 446                'Insert + Erase Time As A Function Of # Items',447                type_str + 'SetInsertEraseAll.png')448            _single_malt(449                functools.partial(_set_insert_erase.run_tests, type_ = type_), 450                [base * i for i in range(1, 10)], 451                100 * num_its, 452                _banyans + ['bintrees', 'btrees', 'set'], 453                'Insert + Erase Time As A Function Of # Items',454                type_str + 'SetInsertEraseAllNoBList.png')455            _single_malt(456                functools.partial(_set_insert_erase.run_tests, type_ = type_), 457                [30 * base * i for i in range(1, 10)], 458                3, 459                ['banyan_red_black_tree', 'banyan_sorted_list', 'set', 'btrees'], 460                'Insert + Erase Time As A Function Of # Items',461                type_str + 'SetInsertEraseCompetitiveLonger.png')462    if _run_create:            463        for type_, type_str in [(int, 'Int'), (str, 'Str')]:464            _single_malt(465                functools.partial(_set_create.run_tests, type_ = type_), 466                [base * i for i in range(1, 10)], 467                30 * num_its, 468                ['banyan_red_black_tree', 'banyan_sorted_list', 'set', 'btrees'], 469                'Create Time As A Function Of # Items',470                type_str + 'SetCreateCompetitiveWithSortedList.png')471                472            _single_malt(473                functools.partial(_set_create.run_tests, type_ = type_),474                [base * i for i in range(1, 10)], 475                30 * num_its, 476                _banyans + ['bintrees', 'blist', 'btrees', 'set'],477                'Create Time As A Function Of # Items',478                type_str + 'SetCreateAll.png')479            _single_malt(480                functools.partial(_set_create.run_tests, type_ = type_),481                [base * i for i in range(1, 10)], 482                30 * num_its, 483                _banyans + ['btrees', 'set'],484                'Create Time As A Function Of # Items',...test_support.py
Source:test_support.py  
1import datetime2import collections3from mobaas.common import support4from mobaas.common import config5from mobaas.tests import run_tests6def test_calc_minute_of_day():7    time1 = datetime.time(hour=0, minute=1, second=1)8    time2 = datetime.time(hour=1, minute=0, second=1)9    time3 = datetime.time(hour=0, minute=0, second=0)10    time4 = datetime.time(hour=23, minute=59, second=59)11    value1 = support.calc_minute_of_day(time1)12    value2 = support.calc_minute_of_day(time2)13    value3 = support.calc_minute_of_day(time3)14    value4 = support.calc_minute_of_day(time4)15    run_tests.compare_answer(value1, 1, "minute of day = 1")16    run_tests.compare_answer(value2, 60, "minute of day = 2")17    run_tests.compare_answer(value3, 0, "minute of day = 3")18    run_tests.compare_answer(value4, 1439, "minute of day = 4")19def test_calc_day():20    monday = support.calc_day(datetime.date(year=2014, month=06, day=30))21    tuesday = support.calc_day(datetime.date(year=2014, month=07, day=01))22    wednesday = support.calc_day(datetime.date(year=2014, month=07, day=02))23    thursday = support.calc_day(datetime.date(year=2015, month=01, day=15))24    friday = support.calc_day(datetime.date(year=2015, month=01, day=16))25    saturday = support.calc_day(datetime.date(year=2015, month=01, day=17))26    sunday = support.calc_day(datetime.date(year=2015, month=01, day=18))27    run_tests.compare_answer(monday, config.MONDAY, "monday")28    run_tests.compare_answer(tuesday, config.TUESDAY, "tuesday")29    run_tests.compare_answer(wednesday, config.WEDNESDAY, "wednesday")30    run_tests.compare_answer(thursday, config.THURSDAY, "thursday")31    run_tests.compare_answer(friday, config.FRIDAY, "friday")32    run_tests.compare_answer(saturday, config.SATURDAY, "saturday")33    run_tests.compare_answer(sunday, config.SUNDAY, "sunday")34def test_remove_none_from_list():35    l1 = [None, 1, 2, None, 3]36    support.remove_none_from_list(l1)37    run_tests.compare_answer(l1, [1,2,3], "")38def test_create_date_time():39    time_str = "14:30:31"40    date_str = "2014-10-17"41    dt = support.create_date_time(date_str, time_str)42    run_tests.compare_answer(dt.second, 31,"second")43    run_tests.compare_answer(dt.minute, 30,"minute")44    run_tests.compare_answer(dt.hour, 14,"hour")45    run_tests.compare_answer(dt.day, 17,"day")46    run_tests.compare_answer(dt.month, 10,"month")47    run_tests.compare_answer(dt.year, 2014,"year")48def test_create_date_str():49    d = datetime.date(year=2014, month=10, day=17)50    run_tests.compare_answer(support.create_date_str(d), "2014-10-17", "")51def test_create_time_str():52    t = datetime.time(hour=12, minute=30, second=31)53    run_tests.compare_answer(support.create_time_str(t), "12:30:31", "")54def test_time_total_seconds():55    t1 = datetime.time(hour=0, minute=0, second=0)56    t2 = datetime.time(hour=10, minute=10, second=10)57    run_tests.compare_answer(support.time_total_seconds(t1), 0, "total seconds 0")58    run_tests.compare_answer(support.time_total_seconds(t2), 36610, "total seconds 36610")59def test_from_unix_timestamp_to_datetime():60    unix_ts = 68770261001061    dt = support.from_unix_timestamp_ms_to_datetime(unix_ts)62    run_tests.compare_answer(dt.microsecond, 10000, "microsecond")63    run_tests.compare_answer(dt.second, 10,"second")64    run_tests.compare_answer(dt.minute, 30,"minute")65    run_tests.compare_answer(dt.hour, 12,"hour")66    run_tests.compare_answer(dt.day, 17,"day")67    run_tests.compare_answer(dt.month, 10,"month")68    run_tests.compare_answer(dt.year, 1991,"year")69def test_to_unix_timestamp_ms_from_date_and_time():70    t = datetime.time(hour=12, minute=30, second=10, microsecond=6000)71    d = datetime.date(year=1991, month=10, day=17)72    unix_ms = support.to_unix_timestamp_ms_from_date_and_time(d, t)73    run_tests.compare_answer(unix_ms, 687702610006, "")74def test_to_unix_timestamp_from_date_and_time():75    t = datetime.time(hour=12, minute=30, second=10, microsecond=6000)76    d = datetime.date(year=1991, month=10, day=17)77    unix_ms = support.to_unix_timestamp_from_date_and_time(d, t)78    run_tests.compare_answer(unix_ms, 687702610, "")79def test_to_grid():80    l1 = [1, 2, 3, 3, 4, 5, 5]81    grid1 = support.to_grid(l1, 1, lambda x: x, 1, 5)82    run_tests.compare_answer(grid1, [1,2,3,4,5], "grid1")83    l2 = [100, 130, 100, 100, 150, 130, 100]84    grid2 = support.to_grid(l2, 10, lambda x: x, 100, 150)85    run_tests.compare_answer(grid2, [100, None, None, 130, None, 150], "grid2")86def test_find_all_in_list():87    l1 = [1, 5, 2, 3, None, 5]88    indices1 = support.find_all_in_list(l1, 5)89    run_tests.compare_answer(indices1, [1, 5], "indices1")90    l2 = [None, 123, "asd", None, datetime.datetime(year=1991, month=10, day=10)]91    indices2 = support.find_all_in_list(l2, None)92    run_tests.compare_answer(indices2, [0, 3], "indices2")93def test_group_by():94    l1 = [1, 2, 3, 4, 5] * 295    answer1 = collections.OrderedDict({1: [1] * 2, 2: [2] * 2, 3: [3] * 2, 4: [4] * 2, 5: [5] * 2})96    run_tests.compare_answer(support.group_by(l1, lambda x:x), answer1, "group_by 1")97def test_reduce_to_missing_ranges():98    l1 = [1, 2, 10, 40, 41, 50]99    answer1 = [support.Range(3, 9, 1), support.Range(11, 39, 1), support.Range(42, 49, 1)]100    result1 = support.reduce_to_missing_ranges(l1, lambda x: x, 1, 1, 50)101    run_tests.compare_answer(result1, answer1, "missing_support.Ranges 1")102    #Difficult one because one value is outside of the (start value, end value) support.Range while the resolution allows it103    l2 = [9, 11]104    answer2 = [support.Range(1, 6, 3), support.Range(10, 10, 3)]105    result2 = support.reduce_to_missing_ranges(l2, lambda x: x, 3, 1, 10)106    run_tests.compare_answer(result2, answer2, "missing_ranges 2")107def test_ranges_add():108    run_tests.compare_answer(support.Range(1,2,1) + support.Range(2,3,1), [support.Range(1,3,1)], "Testing ranges add (1,2) and (2,3)")109    run_tests.compare_answer(support.Range(1,2,1) + support.Range(3,4,1), [support.Range(1,2,1), support.Range(3,4,1)], "Testing ranges add (1,2) and (3,4)")110    run_tests.compare_answer(support.Range(2,3,1) + support.Range(1,2,1), [support.Range(1,3,1)], "Testing ranges add (2,3) and (1,2)")111    run_tests.compare_answer(support.Range(1,2,1) + support.Range(1,2,1), [support.Range(1,2,1)], "Testing ranges add (1,2) and (1,2)")112def test_ranges_sub():113    #Same ranges114    run_tests.compare_answer(support.Range(1,3,1) - support.Range(1,3,1), [], "Test ranges sub (1,3) - (1,3)")115    116    #Right border overlap117    run_tests.compare_answer(support.Range(1,3,1) - support.Range(2,4,1), [support.Range(1,1,1)], "Test ranges sub (1,3) - (2,4)")118    run_tests.compare_answer(support.Range(1,2,1) - support.Range(2,4,1), [support.Range(1,1,1)], "Test ranges sub (1,2) - (2,4)")119    120    #Left border overlap121    run_tests.compare_answer(support.Range(3,5,1) - support.Range(1,4,1), [support.Range(5,5,1)], "Test ranges sub (3,5) - (1,4)")122    run_tests.compare_answer(support.Range(3,5,1) - support.Range(1,3,1), [support.Range(4,5,1)], "Test ranges sub (3,5) - (1,3)")123    124    #Complete overlap125    run_tests.compare_answer(support.Range(3,5,1) - support.Range(2,6,1), [], "Test ranges sub (3,5) - (2,6)")126    run_tests.compare_answer(support.Range(3,5,1) - support.Range(3,5,1), [], "Test ranges sub (3,5) - (3,5)")127    128    #Falls in129    run_tests.compare_answer(support.Range(2,6,1) - support.Range(3,4,1), [support.Range(2,2,1), support.Range(5,6,1)], "Test ranges sub (2,6) - (3,4)")130    #Falls in but on a border so actually a border overlap131    run_tests.compare_answer(support.Range(2,6,1) - support.Range(4,6,1), [support.Range(2,3,1)], "Test ranges sub (2,6) - (4,6)")132    run_tests.compare_answer(support.Range(2,6,1) - support.Range(2,3,1), [support.Range(4,6,1)], "Test ranges sub (2,6) - (2,3)")133    134def test_ranges_has_overlap():135    #Same ranges136    run_tests.compare_answer(support.Range(1,3,1).has_overlap(support.Range(1,3,1)), True, "Test ranges has overlap (1,3) and (1,3)")137    138    #Right border overlap139    run_tests.compare_answer(support.Range(1,3,1).has_overlap(support.Range(2,4,1)), True, "Test ranges has overlap (1,3) and (2,4)")140    run_tests.compare_answer(support.Range(1,2,1).has_overlap(support.Range(2,4,1)), True, "Test ranges has overlap (1,2) and (2,4)")141    142    #Left border overlap143    run_tests.compare_answer(support.Range(3,5,1).has_overlap(support.Range(1,4,1)), True, "Test ranges has overlap (3,5) and (1,4)")144    run_tests.compare_answer(support.Range(3,5,1).has_overlap(support.Range(1,3,1)), True, "Test ranges has overlap (3,5) and (1,3)")145    146    #Complete overlap147    run_tests.compare_answer(support.Range(3,5,1).has_overlap(support.Range(2,6,1)), True, "Test ranges has overlap (3,5) and (2,6)")148    run_tests.compare_answer(support.Range(3,5,1).has_overlap(support.Range(3,5,1)), True, "Test ranges has overlap (3,5) and (3,5)")149    150    #Falls in151    run_tests.compare_answer(support.Range(2,6,1).has_overlap(support.Range(3,4,1)), True, "Test ranges has overlap (2,6) and (3,4)")152    153    #No overlap154    run_tests.compare_answer(support.Range(1,3,1).has_overlap(support.Range(4,6,1)), False, "Test ranges has overlap (1,3) and (4,6)")155    run_tests.compare_answer(support.Range(4,6,1).has_overlap(support.Range(1,3,1)), False, "Test ranges has overlap (4,6) and (1,3)")156    157def test_ranges_other_same_range():158    #Same range159    run_tests.compare_answer(support.Range(1,3,1).other_same_range(support.Range(1,3,1)), True, "Test ranges other same range (1,3) and (1,3)")160    161    #Right border overlap162    run_tests.compare_answer(support.Range(1,3,1).other_same_range(support.Range(2,4,1)), False, "Test ranges other same range (1,3) and (2,4)")163    164    #Left border overlap165    run_tests.compare_answer(support.Range(3,5,1).other_same_range(support.Range(1,4,1)), False, "Test ranges other same range (3,5) and (1,4)")166    167    #No overlap168    run_tests.compare_answer(support.Range(1,3,1).other_same_range(support.Range(4,6,1)), False, "Test ranges other same range (1,3) and (4,6)")169    170    #Falls in171    run_tests.compare_answer(support.Range(2,6,1).other_same_range(support.Range(3,4,1)), False, "Test ranges other same range (2,6) and (3,4)")172    173    #Complete overlap174    run_tests.compare_answer(support.Range(3,4,1).other_same_range(support.Range(2,6,1)), False, "Test ranges other same range (2,6) and (3,4)")175def test_ranges_other_completely_overlaps():176    #Same range177    run_tests.compare_answer(support.Range(1,3,1).other_completely_overlaps(support.Range(1,3,1)), True, "Test ranges other completely overlaps (1,3) and (1,3)")178    179    #Right border overlap180    run_tests.compare_answer(support.Range(1,3,1).other_completely_overlaps(support.Range(2,4,1)), False, "Test ranges other completely overlaps (1,3) and (2,4)")181    182    #Left border overlap183    run_tests.compare_answer(support.Range(3,5,1).other_completely_overlaps(support.Range(1,4,1)), False, "Test ranges other completely overlaps (3,5) and (1,4)")184    185    #No overlap186    run_tests.compare_answer(support.Range(1,3,1).other_completely_overlaps(support.Range(4,6,1)), False, "Test ranges other completely overlaps (1,3) and (4,6)")187    188    #completely overlaps189    run_tests.compare_answer(support.Range(2,6,1).other_completely_overlaps(support.Range(3,4,1)), False, "Test ranges other completely overlaps (2,6) and (3,4)")190    191    #Complete overlap192    run_tests.compare_answer(support.Range(3,4,1).other_completely_overlaps(support.Range(2,6,1)), True, "Test ranges other completely overlaps (2,6) and (3,4)")193def test_ranges_other_falls_in():194    #Same range195    run_tests.compare_answer(support.Range(1,3,1).other_falls_in(support.Range(1,3,1)), False, "Test ranges other falls in (1,3) and (1,3)")196    197    #Right border overlap198    run_tests.compare_answer(support.Range(1,3,1).other_falls_in(support.Range(2,4,1)), False, "Test ranges other falls in (1,3) and (2,4)")199    200    #Left border overlap201    run_tests.compare_answer(support.Range(3,5,1).other_falls_in(support.Range(1,4,1)), False, "Test ranges other falls in (3,5) and (1,4)")202    203    #No overlap204    run_tests.compare_answer(support.Range(1,3,1).other_falls_in(support.Range(4,6,1)), False, "Test ranges other falls in (1,3) and (4,6)")205    206    #Falls in207    run_tests.compare_answer(support.Range(2,6,1).other_falls_in(support.Range(3,4,1)), True, "Test ranges other falls in (2,6) and (3,4)")208    209    #Complete overlap210    run_tests.compare_answer(support.Range(3,4,1).other_falls_in(support.Range(2,6,1)), False, "Test ranges other falls in (2,6) and (3,4)")211    212def test_ranges_other_overlaps_left_border():213    #Same range214    run_tests.compare_answer(support.Range(1,3,1).other_overlaps_left_border(support.Range(1,3,1)), False, "Test ranges other overlaps left border (1,3) and (1,3)")215    216    #Right border overlap217    run_tests.compare_answer(support.Range(1,3,1).other_overlaps_left_border(support.Range(2,4,1)), False, "Test ranges other overlaps left border (1,3) and (2,4)")218    219    #Left border overlap220    run_tests.compare_answer(support.Range(3,5,1).other_overlaps_left_border(support.Range(1,4,1)), True, "Test ranges other overlaps left border (3,5) and (1,4)")221    222    #No overlap223    run_tests.compare_answer(support.Range(1,3,1).other_overlaps_left_border(support.Range(4,6,1)), False, "Test ranges other overlaps left border (1,3) and (4,6)")224    225    #Falls in226    run_tests.compare_answer(support.Range(2,6,1).other_overlaps_left_border(support.Range(3,4,1)), False, "Test ranges other overlaps left border (2,6) and (3,4)")227    228    #Complete overlap229    run_tests.compare_answer(support.Range(3,4,1).other_overlaps_left_border(support.Range(2,6,1)), False, "Test ranges other overlaps left border (2,6) and (3,4)")230def test_ranges_other_overlaps_right_border():231    #Same range232    run_tests.compare_answer(support.Range(1,3,1).other_overlaps_right_border(support.Range(1,3,1)), False, "Test ranges other overlaps right border (1,3) and (1,3)")233    234    #Right border overlap235    run_tests.compare_answer(support.Range(1,3,1).other_overlaps_right_border(support.Range(2,4,1)), True, "Test ranges other overlaps right border (1,3) and (2,4)")236    237    #Left border overlap238    run_tests.compare_answer(support.Range(3,5,1).other_overlaps_right_border(support.Range(1,4,1)), False, "Test ranges other overlaps right border (3,5) and (1,4)")239    240    #No overlap241    run_tests.compare_answer(support.Range(1,3,1).other_overlaps_right_border(support.Range(4,6,1)), False, "Test ranges other overlaps right border (1,3) and (4,6)")242    243    #Falls in244    run_tests.compare_answer(support.Range(2,6,1).other_overlaps_right_border(support.Range(3,4,1)), False, "Test ranges other overlaps right border (2,6) and (3,4)")245    246    #Complete overlap...test_run_tests.py
Source:test_run_tests.py  
1#!/usr/bin/env python2# All rights reserved. This program and the accompanying materials3# are made available under the terms of the Apache License, Version 2.04# which accompanies this distribution, and is available at5# http://www.apache.org/licenses/LICENSE-2.06import logging7import unittest8import mock9from functest.ci import run_tests10from functest.utils.constants import CONST11from functest.core.testcase import TestCase12class FakeModule(TestCase):13    def run(self):14        return TestCase.EX_OK15    def push_to_db(self):16        return TestCase.EX_OK17    def is_successful(self):18        return TestCase.EX_OK19class RunTestsTesting(unittest.TestCase):20    def setUp(self):21        self.runner = run_tests.Runner()22        mock_test_case = mock.Mock()23        mock_test_case.is_successful.return_value = TestCase.EX_OK24        self.runner.executed_test_cases['test1'] = mock_test_case25        self.runner.executed_test_cases['test2'] = mock_test_case26        self.sep = 'test_sep'27        self.creds = {'OS_AUTH_URL': 'http://test_ip:test_port/v2.0',28                      'OS_USERNAME': 'test_os_username',29                      'OS_TENANT_NAME': 'test_tenant',30                      'OS_PASSWORD': 'test_password'}31        self.test = {'test_name': 'test_name'}32        self.tier = mock.Mock()33        test1 = mock.Mock()34        test1.get_name.return_value = 'test1'35        test2 = mock.Mock()36        test2.get_name.return_value = 'test2'37        attrs = {'get_name.return_value': 'test_tier',38                 'get_tests.return_value': [test1, test2],39                 'get_ci_loop.return_value': 'test_ci_loop',40                 'get_test_names.return_value': ['test1', 'test2']}41        self.tier.configure_mock(**attrs)42        self.tiers = mock.Mock()43        attrs = {'get_tiers.return_value': [self.tier]}44        self.tiers.configure_mock(**attrs)45        self.run_tests_parser = run_tests.RunTestsParser()46    @mock.patch('functest.ci.run_tests.logger.error')47    def test_source_rc_file_missing_file(self, mock_logger_error):48        with mock.patch('functest.ci.run_tests.os.path.isfile',49                        return_value=False), \50                self.assertRaises(Exception):51            self.runner.source_rc_file()52    @mock.patch('functest.ci.run_tests.logger.debug')53    @mock.patch('functest.ci.run_tests.os.path.isfile',54                return_value=True)55    def test_source_rc_file_default(self, *args):56        with mock.patch('functest.ci.run_tests.os_utils.source_credentials',57                        return_value=self.creds):58            self.runner.source_rc_file()59    def test_get_run_dict_if_defined_default(self):60        mock_obj = mock.Mock()61        with mock.patch('functest.ci.run_tests.'62                        'ft_utils.get_dict_by_test',63                        return_value={'run': mock_obj}):64            self.assertEqual(self.runner.get_run_dict('test_name'),65                             mock_obj)66    @mock.patch('functest.ci.run_tests.logger.error')67    def test_get_run_dict_if_defined_missing_config_option(self,68                                                           mock_logger_error):69        with mock.patch('functest.ci.run_tests.'70                        'ft_utils.get_dict_by_test',71                        return_value=None):72            testname = 'test_name'73            self.assertEqual(self.runner.get_run_dict(testname),74                             None)75            mock_logger_error.assert_called_once_with("Cannot get {}'s config "76                                                      "options"77                                                      .format(testname))78        with mock.patch('functest.ci.run_tests.'79                        'ft_utils.get_dict_by_test',80                        return_value={}):81            testname = 'test_name'82            self.assertEqual(self.runner.get_run_dict(testname),83                             None)84    @mock.patch('functest.ci.run_tests.logger.exception')85    def test_get_run_dict_if_defined_exception(self,86                                               mock_logger_except):87        with mock.patch('functest.ci.run_tests.'88                        'ft_utils.get_dict_by_test',89                        side_effect=Exception):90            testname = 'test_name'91            self.assertEqual(self.runner.get_run_dict(testname),92                             None)93            mock_logger_except.assert_called_once_with("Cannot get {}'s config"94                                                       " options"95                                                       .format(testname))96    def test_run_tests_import_test_class_exception(self):97        mock_test = mock.Mock()98        args = {'get_name.return_value': 'test_name',99                'needs_clean.return_value': False}100        mock_test.configure_mock(**args)101        with mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \102            mock.patch('functest.ci.run_tests.Runner.get_run_dict',103                       return_value=None), \104                self.assertRaises(Exception) as context:105            self.runner(mock_test, 'tier_name')106            msg = "Cannot import the class for the test case."107            self.assertTrue(msg in context)108    @mock.patch('functest.ci.run_tests.Runner.source_rc_file')109    @mock.patch('importlib.import_module', name="module",110                return_value=mock.Mock(test_class=mock.Mock(111                    side_effect=FakeModule)))112    @mock.patch('functest.utils.functest_utils.get_dict_by_test')113    def test_run_tests_default(self, *args):114        mock_test = mock.Mock()115        kwargs = {'get_name.return_value': 'test_name',116                  'needs_clean.return_value': True}117        mock_test.configure_mock(**kwargs)118        test_run_dict = {'module': 'test_module',119                         'class': 'test_class'}120        with mock.patch('functest.ci.run_tests.Runner.get_run_dict',121                        return_value=test_run_dict):122            self.runner.clean_flag = True123            self.runner.run_test(mock_test)124        self.assertEqual(self.runner.overall_result,125                         run_tests.Result.EX_OK)126    @mock.patch('functest.ci.run_tests.Runner.run_test',127                return_value=TestCase.EX_OK)128    def test_run_tier_default(self, *mock_methods):129        self.assertEqual(self.runner.run_tier(self.tier),130                         run_tests.Result.EX_OK)131        mock_methods[0].assert_called_with(mock.ANY)132    @mock.patch('functest.ci.run_tests.logger.info')133    def test_run_tier_missing_test(self, mock_logger_info):134        self.tier.get_tests.return_value = None135        self.assertEqual(self.runner.run_tier(self.tier),136                         run_tests.Result.EX_ERROR)137        self.assertTrue(mock_logger_info.called)138    @mock.patch('functest.ci.run_tests.logger.info')139    @mock.patch('functest.ci.run_tests.Runner.run_tier')140    @mock.patch('functest.ci.run_tests.Runner.summary')141    def test_run_all_default(self, *mock_methods):142        CONST.__setattr__('CI_LOOP', 'test_ci_loop')143        self.runner.run_all()144        mock_methods[1].assert_not_called()145        self.assertTrue(mock_methods[2].called)146    @mock.patch('functest.ci.run_tests.logger.info')147    @mock.patch('functest.ci.run_tests.Runner.summary')148    def test_run_all_missing_tier(self, *mock_methods):149        CONST.__setattr__('CI_LOOP', 'loop_re_not_available')150        self.runner.run_all()151        self.assertTrue(mock_methods[1].called)152    @mock.patch('functest.ci.run_tests.Runner.source_rc_file',153                side_effect=Exception)154    @mock.patch('functest.ci.run_tests.Runner.summary')155    def test_main_failed(self, *mock_methods):156        kwargs = {'test': 'test_name', 'noclean': True, 'report': True}157        args = {'get_tier.return_value': False,158                'get_test.return_value': False}159        self.runner._tiers = mock.Mock()160        self.runner._tiers.configure_mock(**args)161        self.assertEqual(self.runner.main(**kwargs),162                         run_tests.Result.EX_ERROR)163        mock_methods[1].assert_called_once_with()164    @mock.patch('functest.ci.run_tests.Runner.source_rc_file')165    @mock.patch('functest.ci.run_tests.Runner.run_test',166                return_value=TestCase.EX_OK)167    @mock.patch('functest.ci.run_tests.Runner.summary')168    def test_main_tier(self, *mock_methods):169        mock_tier = mock.Mock()170        test_mock = mock.Mock()171        test_mock.get_name.return_value = 'test1'172        args = {'get_name.return_value': 'tier_name',173                'get_tests.return_value': [test_mock]}174        mock_tier.configure_mock(**args)175        kwargs = {'test': 'tier_name', 'noclean': True, 'report': True}176        args = {'get_tier.return_value': mock_tier,177                'get_test.return_value': None}178        self.runner._tiers = mock.Mock()179        self.runner._tiers.configure_mock(**args)180        self.assertEqual(self.runner.main(**kwargs),181                         run_tests.Result.EX_OK)182        mock_methods[1].assert_called()183    @mock.patch('functest.ci.run_tests.Runner.source_rc_file')184    @mock.patch('functest.ci.run_tests.Runner.run_test',185                return_value=TestCase.EX_OK)186    def test_main_test(self, *mock_methods):187        kwargs = {'test': 'test_name', 'noclean': True, 'report': True}188        args = {'get_tier.return_value': None,189                'get_test.return_value': 'test_name'}190        self.runner._tiers = mock.Mock()191        self.runner._tiers.configure_mock(**args)192        self.assertEqual(self.runner.main(**kwargs),193                         run_tests.Result.EX_OK)194        mock_methods[0].assert_called_once_with('test_name')195    @mock.patch('functest.ci.run_tests.Runner.source_rc_file')196    @mock.patch('functest.ci.run_tests.Runner.run_all')197    @mock.patch('functest.ci.run_tests.Runner.summary')198    def test_main_all_tier(self, *mock_methods):199        kwargs = {'test': 'all', 'noclean': True, 'report': True}200        args = {'get_tier.return_value': None,201                'get_test.return_value': None}202        self.runner._tiers = mock.Mock()203        self.runner._tiers.configure_mock(**args)204        self.assertEqual(self.runner.main(**kwargs),205                         run_tests.Result.EX_OK)206        mock_methods[1].assert_called_once_with()207    @mock.patch('functest.ci.run_tests.Runner.source_rc_file')208    @mock.patch('functest.ci.run_tests.Runner.summary')209    def test_main_any_tier_test_ko(self, *mock_methods):210        kwargs = {'test': 'any', 'noclean': True, 'report': True}211        args = {'get_tier.return_value': None,212                'get_test.return_value': None}213        self.runner._tiers = mock.Mock()214        self.runner._tiers.configure_mock(**args)215        self.assertEqual(self.runner.main(**kwargs),216                         run_tests.Result.EX_ERROR)217if __name__ == "__main__":218    logging.disable(logging.CRITICAL)...test.py
Source:test.py  
...43		view.insert(edit, view.size(),44			"FAILED! Input: \"" + init_with_carets +45			"\", Expected: \"" + result_with_carets +46			"\", Result: \"" + actual_result + "\"\n")47def run_tests(view, edit, command, tests):48	write(view, edit, "========================================")49	write(view, edit, "Testing " + command + "\n")50	for test in tests:51		run_test(view, edit, command, test)52	write(view, edit, "")53def paredit_test_insertion(view, edit):54	run_tests(view, edit,55		"paredit_open_round",56		[57			["|", "(|)"]58		,	["(|)", "((|))"]59		,	["|hel|lo", "(|hel)lo"]60		,	["(def s \"hel|lo\")", "(def s \"hel(|lo\")"]61		,	["; |", "; (|"]62		])63	run_tests(view, edit,64		"paredit_close_round",65		[66			["|", "|"]67		,	["(|)", "()|"]68		,	["(|  )", "()|"]69		,	["(def s \"hel|lo\")", "(def s \"hel)|lo\")"]70		,	["; |", "; )|"]71		,	["(def |a 3)", "(def a 3)|"]72		,	["(def |a 3    )", "(def a 3)|"]73		])74	run_tests(view, edit,75		"paredit_close_round_and_newline",76		[77			["(defn f (x|   ))", "(defn f (x)\n  |)"]78		])79	run_tests(view, edit,80		"paredit_open_square",81		[82			["|", "[|]"]83		,	["[|]", "[[|]]"]84		,	["hell|o w|orld", "hell[|o w]orld"]85		])86	run_tests(view, edit,87		"paredit_doublequote",88		[89			["|", "\"|\""]90		,	["(def a \"|\")", "(def a \"\"|)"]91		,	["(def a \"| \")", "(def a \"\\\"| \")"]92		,	["|hello world|", "\"|hello world|\""]93		])94	run_tests(view, edit,95		"paredit_comment_dwim",96		[97			["(foo |bar) ; baz", "(foo bar) ; |baz"]98		,	["(foo |bar)", "(foo bar) ;|"]99		])100	run_tests(view, edit,101		"paredit_newline",102		[103			["|", "\n|"]104		,	["(defn add1 [x] | (+ x 1))", "(defn add1 [x]\n  |(+ x 1))"]105		])106def paredit_test_deleting_killing(view, edit):107	run_tests(view, edit,108		"paredit_forward_delete",109		[110			["(quu|x \"zot\")", "(quu| \"zot\")"]111		,	["(quux |\"zot\")", "(quux \"|zot\")"]112		,	["(quux \"|zot\")", "(quux \"|ot\")"]113		,	["(quux \"z|(ot\")", "(quux \"z|ot\")"]114		,	["(quux \"|\")", "(quux |)"]115		,	["(quux \"|\\\"\")", "(quux \"|\")"]116		,	["(foo (|) bar)", "(foo | bar)"]117		,	["(foo [|] bar)", "(foo | bar)"]118		,	["|(foo bar)", "(|foo bar)"]119		,	["|[hello world]", "[|hello world]"]120		,	["|{:a 3 :b 4}", "{|:a 3 :b 4}"]121		,	["(hello|)", "(hello)|"]122		,	["; |(", "; |"]123		,	["|()|", "|"]124		,	["|[][]|", "|"]125		,	["(fo|o (bar)| baz)", "(fo| baz)"]126		,	["(fo|o (bar|) baz)", "(fo| (bar) baz)"]127		,	["(defn f1 [coll f |x]| (conj (map f coll) x))",128			 "(defn f1 [coll f |] (conj (map f coll) x))"]129		,	["|(def a 3) ; (|", "|"]130		])131	run_tests(view, edit,132		"paredit_backward_delete",133		[134			["(\"zot\" q|uux)", "(\"zot\" |uux)"]135		,	["(\"zot\"| quux)", "(\"zot|\" quux)"]136		,	["(\"zot|\" quux)", "(\"zo|\" quux)"]137		,	["(quux \"z(|ot\")", "(quux \"z|ot\")"]138		,	["(quux \"|\")", "(quux |)"]139		,	["(quux \"\\\"|\")", "(quux \"|\")"]140		,	["(foo (|) bar)", "(foo | bar)"]141		,	["(foo [|] bar)", "(foo | bar)"]142		,	["(foo {|} bar)", "(foo | bar)"]143		,	["(foo bar)|", "(foo bar|)"]144		,	["[foo bar]|", "[foo bar|]"]145		,	["{:a 3 :b 4}|", "{:a 3 :b 4|}"]146		,	["(|foo bar)", "|(foo bar)"]147		,	["[|foo bar]", "|[foo bar]"]148		,	["{|:a 3 :b 4}", "|{:a 3 :b 4}"]149		,	["; (|", "; |"]150		])151	run_tests(view, edit,152		"paredit_kill",153		[154			["(|foo bar)", "(|)"]155		,	["(|)", "|"]156		,	["(  | )", "|"]157		,	["(foo |bar)", "(foo |)"]158		,	["(foo \"|bar baz\" quux)", "(foo \"|\" quux)"]159		,	["(foo \"bar |baz\" quux)", "(foo \"bar |\" quux)"]160		,	["[1 2| 3]", "[1 2|]"]161		,	["{:a |3 :b 4}", "{:a |}"]162		,	["(foo)| ; Bar", "(foo)|"]163		])164	run_tests(view, edit,165		"paredit_kill_expression",166		[167			["(foo| bar)", "(|)"]168		,	["(foo \"|bar baz\" quux)", "(foo \"|\" quux)"]169		,	["(foo \"bar |baz\" quux)", "(foo \"|\" quux)"]170		,	["[1 2| 3]", "[|]"]171		,	["{:a |3 :b 4}", "{|}"]172		,	["(foo)| ; Bar", "|"]173		])174	run_tests(view, edit,175		"paredit_forward_kill_word",176		[177			["|(foo bar)", "(| bar)"]178		,	["(| bar)", "(|)"]179		])180	run_tests(view, edit,181		"paredit_backward_kill_word",182		[183			["(quux)|", "(|)"]184		,	["(foo |)", "(|)"]185		])186def paredit_test_movement_navigation(view, edit):187	run_tests(view, edit,188		"paredit_forward",189		[190			["(foo |(bar baz) quux)", "(foo (bar baz)| quux)"]191		,	["(foo (bar baz)|)", "(foo (bar baz))|"]192		,	["(f|oo (bar baz))", "(foo| (bar baz))"]193		,	["(foo)| (bar)", "(foo) (bar)|"]194		,	["(foo)|\n(bar)", "(foo)\n(bar)|"]195		])196	run_tests(view, edit,197		"paredit_backward",198		[199			["(foo (bar baz)| quux)", "(foo |(bar baz) quux)"]200		,	["(|(foo) bar)", "|((foo) bar)"]201		,	["(foo) (bar)|", "(foo) |(bar)"]202		,	["(foo) |(bar)", "|(foo) (bar)"]203		,	["(foo)\n|(bar)", "|(foo)\n(bar)"]204		])205	run_tests(view, edit,206		"paredit_forward_up",207		[208			["(foo (bar baz|))", "(foo (bar baz)|)"]209		,	["(foo (bar| baz))", "(foo (bar baz)|)"]210		])211	run_tests(view, edit,212		"paredit_forward_down",213		[214			["(foo |(bar baz))", "(foo (|bar baz))"]215		,	["(|foo (bar baz))", "(foo (|bar baz))"]216		])217	run_tests(view, edit,218		"paredit_backward_up",219		[220			["(foo (|bar baz))", "(foo |(bar baz))"]221		,	["(foo (bar baz|))", "(foo |(bar baz))"]222		])223	run_tests(view, edit,224		"paredit_backward_down",225		[226			["(foo (bar baz)|)", "(foo (bar baz|))"]227		,	["(foo (bar baz) baz|)", "(foo (bar baz|) baz)"]228		])229def paredit_test_depth_changing(view, edit):230	run_tests(view, edit,231		"paredit_wrap_round",232		[233			["(foo |bar baz)", "(foo (|bar) baz)"]234		,	["(foo| (bar) (baz))", "(foo (|(bar)) (baz))"]235		,	["(foo| \"bar\")", "(foo (|\"bar\"))"]236		,	["(foo |bar| baz)", "(foo (|bar) baz)"]237		])238	run_tests(view, edit,239		"paredit_wrap_square",240		[241			["(foo |bar baz)", "(foo [|bar] baz)"]242		])243	run_tests(view, edit,244		"paredit_wrap_curly",245		[246			["(foo |bar baz)", "(foo {|bar} baz)"]247		])248	run_tests(view, edit,249		"paredit_splice_sexp",250		[251			["(foo (bar| baz) quux)", "(foo bar| baz quux)"]252		,	["(def a \"hello| world\")", "(def a hello| world)"]253		,	["(def a \"hello world\"|)", "def a \"hello world\"|"]254		,	["(def a {|:a 3 :b 4})", "(def a |:a 3 :b 4)"]255		,	["(def a {:a 3 :b 4|})", "(def a :a 3 :b 4|)"]256		])257	run_tests(view, edit,258		"paredit_splice_sexp_killing_backward",259		[260			["[1 2 |3 4]", "|3 4"]261		,	["(def a |[1 2 3 4])", "|[1 2 3 4]"]262		,	["(def a \"hell|o world!\")", "(def a |o world!)"]263		])264	run_tests(view, edit,265		"paredit_splice_sexp_killing_forward",266		[267			["[1 2 |3 4]", "1 2 |"]268		,	["(def a |[1 2 3 4])", "def a |"]269		,	["(def a \"hell|o world!\")", "(def a hell|)"]270		])271	run_tests(view, edit,272		"paredit_raise_sexp",273		[274			["[1 2 |3 4]", "|3"]275		,	["(def a |[1 2 3 4])", "|[1 2 3 4]"]276		,	["(def a |:bla)", "|:bla"]277		,	["(def a [1 2 |:hello :world])", "(def a |:hello)"]278		,	["(def a [1 2 3|])", "(def a |)"]279		])280def paredit_test_barfage_slurpage(view, edit):281	run_tests(view, edit,282		"paredit_forward_slurp_sexp",283		[284			["(foo (bar |baz) quux zot)", "(foo (bar |baz quux) zot)"]285		,	["(a b ((c| d)) e f)", "(a b ((c| d) e) f)"]286		,	["(a b ((c| d) e) f)", "(a b ((c| d e)) f)"]287		])288	run_tests(view, edit,289		"paredit_forward_barf_sexp",290		[291			["(foo (bar |baz quux) zot)", "(foo (bar |baz) quux zot)"]292		,	["(f (b |z q) t)", "(f (b |z) q t)"]293		,	["(defn f1 [coll f x] (conj (m|ap f coll x)))",294			 "(defn f1 [coll f x] (conj (m|ap f coll) x))"]295		,	["(defn f1 [coll f x] (conj (m|ap f coll) x))",296			 "(defn f1 [coll f x] (conj (m|ap f) coll x))"]297		,	["(defn f1 [coll f x] (conj (m|ap f) coll x))",298			 "(defn f1 [coll f x] (conj (m|ap) f coll x))"]299		])300	run_tests(view, edit,301		"paredit_backward_slurp_sexp",302		[303			["(foo bar (baz| quux) zot)", "(foo (bar baz| quux) zot)"]304		])305	run_tests(view, edit,306		"paredit_backward_barf_sexp",307		[308			["(foo (bar baz| quux) zot)", "(foo bar (baz| quux) zot)"]309		,	["(f (b |z q) t)", "(f b (|z q) t)"]310		])311def paredit_test_miscellaneous(view, edit):312	run_tests(view, edit,313		"paredit_split_sexp",314		[315			["(hello| world)", "(hello)| (world)"]316		,	["(hello |world)", "(hello)| (world)"]317		,	["(foo \"hello, |world!\")", "(foo \"hello, \"| \"world!\")"]318		])319	run_tests(view, edit,320		"paredit_join_sexp",321		[322			["(hello)| (world)", "(hello| world)"]323		,	["(foo \"Hello, \"| \"world!\")", "(foo \"Hello, |world!\")"]324		,	["hello-\n|  world", "hello-|world"]325		])326####327#### Commands328class Paredit_test_insertionCommand(sublime_plugin.TextCommand):329	def run(self, edit):330		paredit_test_insertion(self.view, edit)331class Paredit_test_deleting_killingCommand(sublime_plugin.TextCommand):332	def run(self, edit):333		paredit_test_deleting_killing(self.view, edit)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
