Coverage for test_core.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-12-24 08:16 +0100

1# (c) 2024 Martin Wendt; see https://github.com/mar10/benchman 

2# Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php 

3""" """ 

4 

5from benchman import BenchmarkManager, util 

6 

7 

8class TestBenchmarkManager: 

9 # @pytest.mark.xfail(reason="just testing") 

10 def test_bench_init(self, capsys): 

11 bm = BenchmarkManager.singleton() 

12 

13 # bm.run_timings( 

14 # "sort", 

15 # variant="builtin", 

16 # repeat=1, # faster 

17 # iterations=10, # faster 

18 # stmt="""\ 

19 # _ = arr.sort() 

20 # """, 

21 # setup="arr = [3,2,1]", 

22 # sample_size=3, 

23 # # globals={"data": data, "fix": fixtures}, 

24 # ) 

25 

26 assert bm 

27 

28 def test_filter(self): 

29 assert util.split_tokens("a,b,c") == ["a", "b", "c"] 

30 

31 def test_smart_sort_keys(self): 

32 assert sorted(["a", "c", "b"], key=util.smart_sort_key) == ["a", "b", "c"] 

33 assert sorted( 

34 ["Py3.10", "Py3.1", "Py3.9.13", "PyPy 2.3"], key=util.smart_sort_key 

35 ) == [ 

36 "Py3.1", 

37 "Py3.9.13", 

38 "Py3.10", 

39 "PyPy 2.3", 

40 ] 

41 assert sorted(["a 10", "a 9,000.1", "a 1.9"], key=util.smart_sort_key) == [ 

42 "a 1.9", 

43 "a 10", 

44 "a 9,000.1", 

45 ] 

46 assert sorted( 

47 [ 

48 "sort(quick_sort, n=1,000)", 

49 "sort(quick_sort, n=100)", 

50 "sort(quick_sort, n=10)", 

51 ], 

52 key=util.smart_sort_key, 

53 ) == [ 

54 "sort(quick_sort, n=10)", 

55 "sort(quick_sort, n=100)", 

56 "sort(quick_sort, n=1,000)", 

57 ]