这是关于测试环境设置的问题.
在我的项目中,我有一些访问测试数据文件的单元测试.这些单元测试可以通过测试运行器从我的项目目录运行.或者我可以单独运行每个测试文件/模块,例如用于调试目的.
问题是,根据我运行测试的位置,当前目录是不同的.因此,当从项目目录运行这些文件时,打开一个测试数据文件,如下所示,通过提供相对于当前目录的路径将不起作用,因为测试数据文件不在该目录中.
f = open('test_data.ext', 'r')
Run Code Online (Sandbox Code Playgroud)
我想使用__file__来使用相对于当前测试模块的路径,但是当调用__file__的测试模块是单独运行的模块时,这不起作用.
人们一般如何解决这个问题?
控制器将a添加UISegmentedControl到导航栏.分段控件添加到viewDidLoad控制器方法的导航栏中,但实际段在viewDidLoad调用后动态创建.
显示视图时,我无法自动调整分段大小.他们都被压扁了,就像在这篇文章中一样,虽然决议不适用于此.如果在将分段控件添加到导航栏的右侧项目之前添加了段(打破了代码的动态特性),则会自动调整它们的大小并在显示视图时看起来很好.
这是我的代码的精简版本,如下所示.我错过了什么?
@implementation MyController
- (void)viewDidLoad {
// segmentedControl is an ivar
segmentedControl = [UISegmentedControl alloc] initWithItems:[NSArray array]];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl] autorelease];
self.navigationController.navigationBar.topItem.rightBarButtonItem = barButtonItem;
}
- (void)someMethodCalledAfterViewDidLoad {
[segmentedControl insertSegmentWithTitle:@"a title"
atIndex:0
animated:NO];
}
@end
Run Code Online (Sandbox Code Playgroud) 我正在尝试根据其文本使用 AppleScript 选择大纲的特定行。
这是我正在考虑的(但不起作用):
repeat with aRow in rows of outline 1 of scroll area 1 of splitter group 1 of window 1
set t to text of cell of aRow
if t starts with "some text" then select aRow
end repeat
Run Code Online (Sandbox Code Playgroud)
问题是这text of cell of aRow并没有解决我认为应该的问题。我使用了辅助功能检查器来确认对象层次结构。我试过在行上使用“UI Elements”来查看哪些元素是可访问的,但它没有返回任何有用的东西。所以我没主意了!我错过了什么?
我正在测试从 Django 2.1.7 到 2.2.12 的应用程序更新。运行单元测试时出现错误,归结为模型对象不可哈希:
Station.objects.all().delete()
py37\lib\site-packages\django\db\models\query.py:710: in delete
collector.collect(del_query)
py37\lib\site-packages\django\db\models\deletion.py:192: in collect
reverse_dependency=reverse_dependency)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ …Run Code Online (Sandbox Code Playgroud)