我有一个Python项目,其中包含一些已经实现的测试,我想开始对它们进行基准测试,以便我可以比较代码,服务器等的性能.以类似于Nose的方式定位文件没有问题,因为无论如何我在所有测试文件的名称中都有"测试".但是,我在尝试动态执行这些测试时遇到了一些麻烦.
到目前为止,我能够运行一个脚本,它将目录路径作为参数,并返回一个文件路径列表,如下所示:
def getTestFiles(directory):
fileList = []
print "Searching for 'test' in " + directory
if not os.path.isdir(os.path.dirname(directory)):
# throw error
raise InputError(directory, "Not a valid directory")
else:
for root, dirs, files in os.walk(directory):
#print files
for f in files:
if "test" in f and f.endswith(".py"):
fileList.append(os.path.join(root, f))
return fileList
# returns a list like this:
# [ 'C:/Users/myName/Desktop/example1_test.py',
# 'C:/Users/myName/Desktop/example2_test.py',
# 'C:/Users/myName/Desktop/folder1/example3_test.py',
# 'C:/Users/myName/Desktop/folder2/example4_test.py'... ]
Run Code Online (Sandbox Code Playgroud)
问题是这些文件可能有不同的语法,我正试图弄清楚如何处理.例如:
TestExampleOne:
import dummy1
import dummy2
import dummy3
class TestExampleOne(unittest.TestCase):
@classmethod
def setUpClass(cls):
# …Run Code Online (Sandbox Code Playgroud) 我有一个函数,我写了这里显示几个图:
def plot_price_series(df, ts1, ts2):
# price series line graph
fig = plt.figure()
ax1 = fig.add_subplot(221)
ax1.plot(df.index, df[ts1], label=ts1)
ax1.plot(df.index, df[ts2], label=ts2)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))
ax1.set_xlim(df.index[0], df.index[-1])
ax1.grid(True)
fig.autofmt_xdate()
ax1.set_xlabel('Month/Year')
ax1.set_ylabel('Price')
ax1.set_title('%s and %s Weekly Prices' % (ts1, ts2))
plt.legend()
# Spread
ax2 = fig.add_subplot(222)
ax2.plot(df.index, df[ts2] - df[ts1], label=ts2 + " vs " + ts1 + " spread")
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))
ax2.set_xlim(df.index[0], df.index[-1])
ax2.grid(True)
fig.autofmt_xdate()
ax2.set_xlabel('Month/Year')
ax2.set_ylabel('Spread')
ax2.set_title('%s and %s Weekly Spread' % (ts1, ts2))
# Scatter w/ line of least …Run Code Online (Sandbox Code Playgroud) 我在这样的Excel文件中有值:
QR | QR AVG | val1 |
q1 5
q1 3
q1 4
q2 7
q2 9
q3 10
q3 11
q3 12
q3 11
q4 5
q5 5
q5 7
Run Code Online (Sandbox Code Playgroud)
我希望QR AVG字段表示由不同QR值划分的平均值.换句话说,我想在计算后得到以下数值:
QR | QR AVG | val1 |
q1 4 5
q1 4 3
q1 4 4
q2 8 7
q2 8 9
q3 11 10
q3 11 11
q3 11 12
q3 11 11
q4 5 5
q5 6 5
q5 6 7
Run Code Online (Sandbox Code Playgroud)
我不知道我将拥有的确切行数,并且我会间歇性地将行随机添加到表中.
如果可能的话,我宁愿不写宏来做这件事.知道我怎么会这样做吗?
我有代码:
USE pricingdb
go
CREATE TABLE dbo.Fin_Options_Specs (
column1 NVARCHAR(255),
column2 NVARCHAR(255),
column3 DOUBLE
);
Go
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用SQL创建一个3列表.列的名称将在稍后更改,这不是问题.但是,我一直在收到错误
"''附近的语法不正确'.'"
我有一个 CSV 文件,每天都会根据从网站上抓取的一些数据进行更新。该文件的格式并不理想,但不幸的是还有其他依赖项导致它,所以我无法更改数字的格式化方式。我每天都会阅读已有的 CSV,然后在信息出现时使用每天的数据进行更新。该文件的格式如下:
2015-06-29| | 2015-06-28| | 2015-06-27| ...
col1 | col2 | col1 | col2 | col1 | col2
10 | 3 | 103.4 | 6.6 | 103.2 | 4.3
1028 | 5 | 102.4 | 6.2 | 103.3 | 2.2
90 | 6 | 91.7 | 5.0 | 93.1 | 2.4
105 | 1 | 100.8 | 5.5 | 100.9 | 1.7
345 | 7 | 103.0 | 6.1 | 102.9 | 6.3
53 | 3 | …Run Code Online (Sandbox Code Playgroud) python ×3
pandas ×2
average ×1
benchmarking ×1
csv ×1
excel ×1
excel-2007 ×1
matplotlib ×1
sql-server ×1
statistics ×1
testing ×1
unit-testing ×1