\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
xam_csv_speed.py¶
View page sourceExample and Test of Python csv_speed¶
Source Code¶
import os
import cmpad
import pathlib
import platform
import csv
#
# xam_csv_speed
def xam_csv_speed() :
#
# ok
ok = True
#
# build_dir
this_file = pathlib.Path(__file__).resolve()
repo_dir = this_file.parent.parent.parent
build_dir = repo_dir.joinpath('build')
#
# file_name
file_name = str ( build_dir.joinpath('csv_speed.csv') )
if os.path.exists( file_name ) :
os.remove( file_name )
#
# min_time
min_time = 0.1
#
# package
package = 'none'
#
# algorithm
algorithm = 'det_by_minor'
#
# special
special = False
#
# option
option = { 'n_arg' : 4, 'n_other' : 0, 'time_setup' : False }
#
# fun_obj
fun_obj = cmpad.det_by_minor()
#
# rate
rate = cmpad.fun_speed(fun_obj, option, min_time)
#
# csv_speed
cmpad.csv_speed(
file_name, rate, min_time, package, algorithm, special, option
)
#
# csv_table
file_obj = open(file_name, 'r')
reader = csv.DictReader(file_obj)
csv_table = list()
for row in reader :
csv_table.append(row)
file_obj.close()
#
# language
language = 'python'
#
# compiler
compiler = platform.python_implementation()+'-'+platform.python_version()
#
# ok
ok = len( csv_table ) == 1
#
# ok
col_names = [
'rate',
'min_time',
'package',
'algorithm',
'n_arg',
'n_other',
'time_setup',
'date',
'compiler',
'debug',
'language',
'special'
]
ok = list( csv_table[0].keys() ) == col_names
#
# str2bool
str2bool = { 'true' : True, 'false' : False }
#
# ok
row = csv_table[0]
ok &= float( row['min_time'] ) == min_time
ok &= row['package'] == 'none'
ok &= int( row['n_arg'] ) == option['n_arg']
ok &= int( row['n_other'] ) == option['n_other']
ok &= str2bool[ row['time_setup'] ] == option['time_setup']
ok &= row['compiler'] == compiler
ok &= row['language'] == 'python'
ok &= row['special'] == 'false'
#
return ok
#
# test_csv_speed
def test_csv_speed() :
assert xam_csv_speed() == True