Python pytest.approx() Examples
The following are 30
code examples of pytest.approx().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pytest
, or try the search function
.
Example #1
Source File: test_mplcursors.py From mplcursors with MIT License | 6 votes |
def test_errorbar(ax): ax.errorbar(range(2), range(2), [(1, 1), (1, 2)]) cursor = mplcursors.cursor() assert len(cursor.artists) == 1 _process_event("__mouse_click__", ax, (0, 2), 1) assert len(cursor.selections) == 0 _process_event("__mouse_click__", ax, (.5, .5), 1) assert cursor.selections[0].target == approx((.5, .5)) assert _parse_annotation( cursor.selections[0], "x=(.*)\ny=(.*)") == approx((.5, .5)) _process_event("__mouse_click__", ax, (0, 1), 1) assert cursor.selections[0].target == approx((0, 0)) assert _parse_annotation( cursor.selections[0], r"x=(.*)\ny=\$(.*)\\pm(.*)\$") == (0, 0, 1) _process_event("__mouse_click__", ax, (1, 2), 1) sel, = cursor.selections assert sel.target == approx((1, 1)) assert _parse_annotation( sel, r"x=(.*)\ny=\$(.*)_\{(.*)\}\^\{(.*)\}\$") == (1, 1, -1, 2)
Example #2
Source File: test_ciftify_seed_corr.py From ciftify with MIT License | 6 votes |
def test_ciftify_seedcorr_cifti_output_nifti_seed(output_dir, subcort_images_dir): seedcorr_output = os.path.join(output_dir, 'seedcorr.dscalar.nii') run(['ciftify_seed_corr', '--debug', '--roi-label 4', '--outputname', seedcorr_output, test_dtseries, os.path.join(subcort_images_dir, 'rois.nii.gz')]) meants5, labels5 = get_the_5_rois_meants_outputs( seedcorr_output, output_dir, custom_dlabel) print(meants5) print(labels5) assert os.path.isfile(seedcorr_output) assert pytest.approx(meants5.loc[0,0], 0.001) == 0.1256 assert pytest.approx(meants5.loc[1,0], 0.001) == 0.3094 assert pytest.approx(meants5.loc[3,0], 0.001) == 0.3237 assert pytest.approx(meants5.loc[4,0], 0.001) == 0.1458
Example #3
Source File: test_ciftify_seed_corr.py From ciftify with MIT License | 6 votes |
def test_ciftify_seedcorr_cifti_output_with_mask(output_dir, left_hemisphere_dir): seedcorr_output = os.path.join(output_dir, 'seedcorr.dscalar.nii') run(['ciftify_seed_corr', '--debug', '--outputname', seedcorr_output, '--weighted', '--mask', os.path.join(left_hemisphere_dir, 'mask_L.dscalar.nii'), test_dtseries, weighted_dscalar]) meants5, labels5 = get_the_5_rois_meants_outputs(seedcorr_output, output_dir, custom_dlabel) assert os.path.isfile(seedcorr_output) print(meants5) print(labels5) assert pytest.approx(meants5.loc[0,0], 0.001) == 0.0875 assert pytest.approx(meants5.loc[1,0], 0.001) == 0 assert pytest.approx(meants5.loc[3,0], 0.001) == 0
Example #4
Source File: test_timer.py From rift-python with Apache License 2.0 | 6 votes |
def test_attributes(context): # Timer1: periodic interval 0.8 sec timer1 = timer.Timer( interval=0.8, expire_function=context.timer1_expired) # Timer2: one-shot interval 0.7 sec timer2 = timer.Timer( interval=0.7, expire_function=context.timer2_expired, periodic=False) assert timer1.running() is True assert timer1.interval() == pytest.approx(0.8) assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer1.remaining_time_str()) assert timer2.running() is True assert timer2.interval() == pytest.approx(0.7) assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer2.remaining_time_str()) time.sleep(1.0) timer.TIMER_SCHEDULER.trigger_all_expired_timers() assert timer1.running() is True assert timer1.interval() == pytest.approx(0.8) assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer1.remaining_time_str()) assert timer2.running() is False assert timer2.interval() == pytest.approx(0.7) assert timer2.remaining_time_str() == "Stopped"
Example #5
Source File: test_mplcursors.py From mplcursors with MIT License | 6 votes |
def test_move(ax, plotter): plotter(ax, [0, 1, 2], [0, 1, np.nan]) cursor = mplcursors.cursor() # Nothing happens with no cursor. _process_event("key_press_event", ax, (.123, .456), "shift+left") assert len(cursor.selections) == 0 # Now we move the cursor left or right. if plotter in [Axes.plot, Axes.errorbar]: _process_event("__mouse_click__", ax, (.5, .5), 1) assert tuple(cursor.selections[0].target) == approx((.5, .5)) _process_event("key_press_event", ax, (.123, .456), "shift+up") _process_event("key_press_event", ax, (.123, .456), "shift+left") elif plotter is Axes.scatter: _process_event("__mouse_click__", ax, (0, 0), 1) _process_event("key_press_event", ax, (.123, .456), "shift+up") assert tuple(cursor.selections[0].target) == (0, 0) assert cursor.selections[0].target.index == 0 _process_event("key_press_event", ax, (.123, .456), "shift+right") assert tuple(cursor.selections[0].target) == (1, 1) assert cursor.selections[0].target.index == 1 # Skip through nan. _process_event("key_press_event", ax, (.123, .456), "shift+right") assert tuple(cursor.selections[0].target) == (0, 0) assert cursor.selections[0].target.index == 0
Example #6
Source File: test_notebook_introspective_rationale_explainer.py From interpret-text with MIT License | 6 votes |
def test_text_classification_introspective_rationale(notebooks, tmp): notebook_path = notebooks["tc_introspective_rationale"] pm.execute_notebook( notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME, parameters=dict( DATA_FOLDER=tmp, CUDA=torch.cuda.is_available(), QUICK_RUN=False, MODEL_SAVE_DIR=tmp ), ) result = sb.read_notebook(OUTPUT_NOTEBOOK).scraps.data_dict print(result) assert pytest.approx(result["accuracy"], 0.72, abs=ABS_TOL) assert pytest.approx(result["anti_accuracy"], 0.69, abs=ABS_TOL) assert pytest.approx(result["sparsity"], 0.17, abs=ABS_TOL)
Example #7
Source File: test_notebook_unified_information_explainer.py From interpret-text with MIT License | 6 votes |
def test_text_classification_unified_information(notebooks, tmp): notebook_path = notebooks["tc_unified_information"] pm.execute_notebook( notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME, parameters=dict( DATA_FOLDER=tmp, BERT_CACHE_DIR=tmp, BATCH_SIZE=32, BATCH_SIZE_PRED=512, NUM_EPOCHS=1, TEST=True, QUICK_RUN=True, ), ) result = sb.read_notebook(OUTPUT_NOTEBOOK).scraps.data_dict assert pytest.approx(result["accuracy"], 0.93, abs=ABS_TOL) assert pytest.approx(result["precision"], 0.93, abs=ABS_TOL) assert pytest.approx(result["recall"], 0.93, abs=ABS_TOL) assert pytest.approx(result["f1"], 0.93, abs=ABS_TOL)
Example #8
Source File: test_serializers.py From figures with MIT License | 6 votes |
def test_has_fields(self): '''Verify the serialized data has the same keys and values as the model Django 2.0 has a convenient method, 'Cast' that will simplify converting values: https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#cast This means that we can retrieve the model instance values as a dict and do a simple ``assert self.serializer.data == queryset.values(...)`` ''' data = self.serializer.data # Hack: Check date and datetime values explicitly assert data['date_for'] == str(self.metrics.date_for) assert dateutil_parse(data['created']) == self.metrics.created assert dateutil_parse(data['modified']) == self.metrics.modified check_fields = self.expected_results_keys - self.date_fields - set(['site']) for field_name in check_fields: db_field = getattr(self.metrics, field_name) if type(db_field) in (float, Decimal, ): assert float(data[field_name]) == pytest.approx(db_field) else: assert data[field_name] == db_field
Example #9
Source File: test_serializers.py From figures with MIT License | 6 votes |
def test_has_fields(self): ''' Initially, doing a limited test of fields as figure out how mamu of the CourseEnrollment model fields and relationships we need to capture. ''' data = self.serializer.data assert data['course_id'] == str(self.model_obj.course_id) # assert data['course']['id'] == str(self.model_obj.course.id) # assert data['course']['display_name'] == self.model_obj.course.display_name # assert data['course']['org'] == self.model_obj.course.org assert dateutil_parse(data['created']) == self.model_obj.created assert data['user']['fullname'] == self.model_obj.user.profile.name for field_name in (self.expected_results_keys - self.special_fields): db_field = getattr(self.model_obj, field_name) if type(db_field) in (float, Decimal, ): assert float(data[field_name]) == pytest.approx(db_field) else: assert data[field_name] == db_field
Example #10
Source File: test_mplcursors.py From mplcursors with MIT License | 6 votes |
def test_steps_mid(ax): ax.plot([0, 1], [0, 1], drawstyle="steps-mid") ax.set(xlim=(-1, 2), ylim=(-1, 2)) cursor = mplcursors.cursor() _process_event("__mouse_click__", ax, (0, 1), 1) assert len(cursor.selections) == 0 _process_event("__mouse_click__", ax, (1, 0), 1) assert len(cursor.selections) == 0 _process_event("__mouse_click__", ax, (.25, 0), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, .25, 0)) _process_event("__mouse_click__", ax, (.5, .5), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, .5, .5)) _process_event("__mouse_click__", ax, (.75, 1), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, .75, 1))
Example #11
Source File: test_ciftify_seed_corr.py From ciftify with MIT License | 6 votes |
def test_ciftify_seedcorr_cifti_output_with_TRfile(output_dir): seedcorr_output = os.path.join(output_dir, 'seedcorr.dscalar.nii') TR_file = os.path.join(output_dir, 'TR_file.txt') with open(TR_file, "w") as text_file: text_file.write('''1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30''') run(['ciftify_seed_corr', '--outputname', seedcorr_output, '--use-TRs', TR_file, '--weighted', test_dtseries, weighted_dscalar]) assert os.path.isfile(seedcorr_output) meants5, labels5 = get_the_5_rois_meants_outputs( seedcorr_output, output_dir, custom_dlabel) assert pytest.approx(meants5.loc[0,0], 0.001) == 0.0929 assert pytest.approx(meants5.loc[1,0], 0.001) == 0.482 assert pytest.approx(meants5.loc[3,0], 0.001) == 0.220
Example #12
Source File: test_h3.py From h3-py with Apache License 2.0 | 6 votes |
def test_h3_to_geo_boundary_geo_json(): out = h3.h3_to_geo_boundary('85283473fffffff', True) expected = [ [-121.91508032705622, 37.271355866731895], [-121.86222328902491, 37.353926450852256], [-121.9235499963016, 37.42834118609435], [-122.0377349642703, 37.42012867767778], [-122.09042892904395, 37.33755608435298], [-122.02910130919, 37.26319797461824], [-121.91508032705622, 37.271355866731895], ] assert len(out) == len(expected) for o, e in zip(out, expected): assert o == approx(e)
Example #13
Source File: test_mot.py From PoseWarper with Apache License 2.0 | 6 votes |
def test_correct_average(): # Tests what is being depicted in figure 3 of 'Evaluating MOT Performance' acc = mm.MOTAccumulator(auto_id=True) # No track acc.update([1, 2, 3, 4], [], []) acc.update([1, 2, 3, 4], [], []) acc.update([1, 2, 3, 4], [], []) acc.update([1, 2, 3, 4], [], []) # Track single acc.update([4], [4], [0]) acc.update([4], [4], [0]) acc.update([4], [4], [0]) acc.update([4], [4], [0]) mh = mm.metrics.create() metr = mh.compute(acc, metrics='mota', return_dataframe=False) assert metr['mota'] == approx(0.2)
Example #14
Source File: test_h3.py From h3-py with Apache License 2.0 | 6 votes |
def test_h3_to_geo_boundary(): out = h3.h3_to_geo_boundary('85283473fffffff') expected = [ [37.271355866731895, -121.91508032705622], [37.353926450852256, -121.86222328902491], [37.42834118609435, -121.9235499963016], [37.42012867767778, -122.0377349642703], [37.33755608435298, -122.09042892904395], [37.26319797461824, -122.02910130919], ] assert len(out) == len(expected) for o, e in zip(out, expected): assert o == approx(e)
Example #15
Source File: test_watson.py From Watson with MIT License | 6 votes |
def test_report_current(mocker, config_dir): mocker.patch('arrow.utcnow', return_value=arrow.get(5000)) watson = Watson( current={'project': 'foo', 'start': 4000}, config_dir=config_dir ) for _ in range(2): report = watson.report( arrow.utcnow(), arrow.utcnow(), current=True, projects=['foo'] ) assert len(report['projects']) == 1 assert report['projects'][0]['name'] == 'foo' assert report['projects'][0]['time'] == pytest.approx(1000) report = watson.report( arrow.utcnow(), arrow.utcnow(), current=False, projects=['foo'] ) assert len(report['projects']) == 0 report = watson.report( arrow.utcnow(), arrow.utcnow(), projects=['foo'] ) assert len(report['projects']) == 0
Example #16
Source File: test_loadlib.py From msl-loadlib with MIT License | 5 votes |
def test_unicode_path(): cls = loadlib.LoadLibrary(u'./tests/uñicödé/Trig.class') import math x = 0.123456 assert cls.lib.Trig.cos(x) == pytest.approx(math.cos(x)) repr(cls) # this should not raise an exception str(cls) # this should not raise an exception cls.gateway.shutdown() if (loadlib.IS_MAC or loadlib.IS_LINUX) and sys.version_info[:2] == (3, 8): # get fatal crash on MacOS & Python 3.8 when importing pythonnet pass else: net = loadlib.LoadLibrary(u'./tests/uñicödé/Namespace.With.Dots-uñicödé.dll', 'net') checker = net.lib.Namespace.With.Dots.Checker() assert checker.IsSuccess() repr(net) # this should not raise an exception str(net) # this should not raise an exception # IMPORTANT: keep the C++ test after loading the unicode version of the .NET DLL # because it tests for additional problems that can occur. # When the unicode version of .NET is loaded the `head` gets appended to sys.path, i.e., # # the shared library must be available in sys.path # head, tail = os.path.split(self._path) # if IS_PYTHON2: # head = head.decode(_encoding) <- this is important # sys.path.append(head) # Without doing head.decode(_encoding) then when loading the unicode version of the C++ DLL # the following error occurred: # UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 29: ordinal not in range(128) # This happens because when doing the search for the unicode version of the C++ DLL in Python 2.7, i.e., # search_dirs = sys.path + os.environ['PATH'].split(os.pathsep) # for directory in search_dirs: # p = os.path.join(directory, _path) <- raised UnicodeDecodeError # the `directory` equaled the encoded version of `head` and so it raised UnicodeDecodeError sys.path.append(u'./tests/uñicödé') bitness = u'64' if loadlib.IS_PYTHON_64BIT else u'32' cpp = loadlib.LoadLibrary(u'cpp_lib' + bitness + u'-uñicödé') assert cpp.lib.add(1, 2) == 3 repr(cpp) # this should not raise an exception str(cpp) # this should not raise an exception
Example #17
Source File: test_mplcursors.py From mplcursors with MIT License | 5 votes |
def test_image_rgb(ax): ax.imshow([[[.1, .2, .3], [.4, .5, .6]]]) cursor = mplcursors.cursor() _process_event("__mouse_click__", ax, (0, 0), 1) sel, = cursor.selections assert _parse_annotation( sel, r"x=(.*)\ny=(.*)\n\[0.1, 0.2, 0.3\]") == approx((0, 0)) _process_event("key_press_event", ax, (.123, .456), "shift+right") sel, = cursor.selections assert _parse_annotation( sel, r"x=(.*)\ny=(.*)\n\[0.4, 0.5, 0.6\]") == approx((1, 0))
Example #18
Source File: test_mplcursors.py From mplcursors with MIT License | 5 votes |
def test_linecollection(ax): ax.eventplot([0, 1]) cursor = mplcursors.cursor() _process_event("__mouse_click__", ax, (0, 0), 1) _process_event("__mouse_click__", ax, (.5, 1), 1) assert len(cursor.selections) == 0 _process_event("__mouse_click__", ax, (0, 1), 1) assert cursor.selections[0].target.index == approx((0, .5))
Example #19
Source File: test_server32.py From msl-loadlib with MIT License | 5 votes |
def test_dotnet(): names = n.get_class_names() assert len(names) == 4 assert 'StringManipulation' in names assert 'DotNetMSL.BasicMath' in names assert 'DotNetMSL.ArrayManipulation' in names assert 'StaticClass' in names assert 9 == n.add_integers(4, 5) assert 0.8 == pytest.approx(n.divide_floats(4., 5.)) assert 458383.926 == pytest.approx(n.multiply_doubles(872.24, 525.525)) assert 108.0 == pytest.approx(n.add_or_subtract(99., 9., True)) assert 90.0 == pytest.approx(n.add_or_subtract(99., 9., False)) a = 7.13141 values = [float(x) for x in range(1000)] net_values = n.scalar_multiply(a, values) for i in range(len(values)): assert a*values[i] == pytest.approx(net_values[i]) assert n.reverse_string('New Zealand') == 'dnalaeZ weN' net_mat = n.multiply_matrices([[1., 2., 3.], [4., 5., 6.]], [[1., 2.], [3., 4.], [5., 6.]]) assert 22.0 == pytest.approx(net_mat[0][0]) assert 28.0 == pytest.approx(net_mat[0][1]) assert 49.0 == pytest.approx(net_mat[1][0]) assert 64.0 == pytest.approx(net_mat[1][1]) assert 33 == n.add_multiple(11, -22, 33, -44, 55) assert 'the experiment worked ' == n.concatenate('the ', 'experiment ', 'worked ', False, 'temporarily') assert 'the experiment worked temporarily' == n.concatenate('the ', 'experiment ', 'worked ', True, 'temporarily')
Example #20
Source File: test_star.py From pyswarms with MIT License | 5 votes |
def test_compute_gbest_return_values(self, swarm, options, topology): """Test if compute_gbest() gives the expected return values""" topo = topology() expected_cost = 1.0002528364353296 expected_pos = np.array( [9.90438476e-01, 2.50379538e-03, 1.87405987e-05] ) pos, cost = topo.compute_gbest(swarm, **options) assert cost == pytest.approx(expected_cost) assert pos == pytest.approx(expected_pos)
Example #21
Source File: test_cells_and_edges.py From h3-py with Apache License 2.0 | 5 votes |
def approx2(a, b): if len(a) != len(b): return False return all( x == pytest.approx(y) for x, y in zip(a, b) )
Example #22
Source File: test_mplcursors.py From mplcursors with MIT License | 5 votes |
def test_nan(ax, plot_args, click, targets): ax.plot(*plot_args) cursor = mplcursors.cursor() _process_event("__mouse_click__", ax, click, 1) assert len(cursor.selections) == len(ax.texts) == len(targets) for sel, target in zip(cursor.selections, targets): assert sel.target == approx(target)
Example #23
Source File: test_mplcursors.py From mplcursors with MIT License | 5 votes |
def test_steps_post(ax): ax.plot([0, 1], [0, 1], drawstyle="steps-post") ax.set(xlim=(-1, 2), ylim=(-1, 2)) cursor = mplcursors.cursor() _process_event("__mouse_click__", ax, (0, 1), 1) assert len(cursor.selections) == 0 _process_event("__mouse_click__", ax, (.5, 0), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, .5, 0)) _process_event("__mouse_click__", ax, (1, .5), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, 1, .5))
Example #24
Source File: test_mplcursors.py From mplcursors with MIT License | 5 votes |
def test_steps_pre(ax): ax.plot([0, 1], [0, 1], drawstyle="steps-pre") ax.set(xlim=(-1, 2), ylim=(-1, 2)) cursor = mplcursors.cursor() _process_event("__mouse_click__", ax, (1, 0), 1) assert len(cursor.selections) == 0 _process_event("__mouse_click__", ax, (0, .5), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, 0, .5)) _process_event("__mouse_click__", ax, (.5, 1), 1) index = cursor.selections[0].target.index assert (index.int, index.x, index.y) == approx((0, .5, 1))
Example #25
Source File: test_mplcursors.py From mplcursors with MIT License | 5 votes |
def test_line(ax, plotter): artist, = plotter(ax, [0, .2, 1], [0, .8, 1], label="foo") cursor = mplcursors.cursor(multiple=True) # Far, far away. _process_event("__mouse_click__", ax, (0, 1), 1) assert len(cursor.selections) == len(ax.texts) == 0 # On the line. _process_event("__mouse_click__", ax, (.1, .4), 1) assert len(cursor.selections) == len(ax.texts) == 1 assert _parse_annotation( cursor.selections[0], "foo\nx=(.*)\ny=(.*)") == approx((.1, .4)) # Not removing it. _process_event("__mouse_click__", ax, (0, 1), 3) assert len(cursor.selections) == len(ax.texts) == 1 # Remove the text label; add another annotation. artist.set_label(None) _process_event("__mouse_click__", ax, (.6, .9), 1) assert len(cursor.selections) == len(ax.texts) == 2 assert _parse_annotation( cursor.selections[1], "x=(.*)\ny=(.*)") == approx((.6, .9)) # Remove both of them (first removing the second one, to test # `Selection.__eq__` -- otherwise it is bypassed as `list.remove` # checks identity first). _process_event(*_get_remove_args(cursor.selections[1])) assert len(cursor.selections) == len(ax.texts) == 1 _process_event(*_get_remove_args(cursor.selections[0])) assert len(cursor.selections) == len(ax.texts) == 0 # Will project on the vertex at (.2, .8). _process_event("__mouse_click__", ax, (.2 - .001, .8 + .001), 1) assert len(cursor.selections) == len(ax.texts) == 1
Example #26
Source File: test_cells_and_edges.py From h3-py with Apache License 2.0 | 5 votes |
def test_edge_boundary(): h1 = '8928308280fffff' h2 = '89283082873ffff' e = h3.get_h3_unidirectional_edge(h1, h2) expected = ( (37.77688044840226, -122.41612835779266), (37.778385004930925, -122.41738797617619) ) out = h3.get_h3_unidirectional_edge_boundary(e) assert out[0] == pytest.approx(expected[0]) assert out[1] == pytest.approx(expected[1])
Example #27
Source File: test_cells_and_edges.py From h3-py with Apache License 2.0 | 5 votes |
def test_hex_edge_length(): expected_in_km = { 0: 1107.712591000, 1: 418.676005500, 2: 158.244655800, 9: 0.174375668, 15: 0.000509713, } out = { res: h3.edge_length(res, unit='km') for res in expected_in_km } assert out == pytest.approx(expected_in_km)
Example #28
Source File: test_cells_and_edges.py From h3-py with Apache License 2.0 | 5 votes |
def test_hex_area(): expected_in_km2 = { 0: 4250546.848, 1: 607220.9782, 2: 86745.85403, 9: 0.1053325, 15: 9e-07, } out = { k: h3.hex_area(k, unit='km^2') for k in expected_in_km2 } assert out == pytest.approx(expected_in_km2)
Example #29
Source File: test_cells_and_edges.py From h3-py with Apache License 2.0 | 5 votes |
def test2(): h = '8928308280fffff' expected = (37.77670234943567, -122.41845932318311) assert h3.h3_to_geo(h) == pytest.approx(expected)
Example #30
Source File: test_watson.py From Watson with MIT License | 5 votes |
def test_report_include_partial_frames(mocker, watson, date_as_unixtime, include_partial, sum_): """Test report building with frames that cross report boundaries 1 event is added that has 2 hours in one day and 1 in the next. The parametrization checks that the report for both days is empty with `include_partial=False` and report the correct amount of hours with `include_partial=False` """ content = json.dumps([[ 3600 * 46, 3600 * 49, "programming", "3e76c820909840f89cabaf106ab7d12a", ["cli"], 1548797432 ]]) mocker.patch('%s.open' % builtins, mocker.mock_open(read_data=content)) date = arrow.get(date_as_unixtime) report = watson.report( from_=date, to=date, include_partial_frames=include_partial, ) assert report["time"] == pytest.approx(sum_, abs=1e-3) # renaming project updates frame last_updated time