我有一个简单的目录结构:
proj/
src/
__init__.py
foo.py
bar.py
test/
__init__.py
test_foo.py
Run Code Online (Sandbox Code Playgroud)
测试_foo.py
import unittest
import sys
sys.path.append('../src')
from src import foo
class TestFoo(unittest.TestCase):
def test_foo(self):
foo.start()
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
foo.py
import bar
def start():
bar.do_stuff()
Run Code Online (Sandbox Code Playgroud)
运行测试时(我使用 vscode),出现以下错误:
Failed to import test module: test_foo
Traceback (most recent call last):
File "~/.pyenv/versions/3.8.6/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "~/.pyenv/versions/3.8.6/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "~/proj/test/test_foo.py", line 6, in <module>
from src import foo
File "~/proj/src/foo.py", line 1, in <module> …Run Code Online (Sandbox Code Playgroud) 我在这里使用AngularFire2版本的代码,我用它来从我的一个组件上的数据库中获取一些成员.
当我在同一个组件中调用此注销时,我遇到了问题.我取消订阅订阅但我仍然在控制台中收到错误说Exception was thrown by user callback. Error: permission_denied at /users/uid.我知道这是因为我不再登录,我的数据库规则不允许这种读取操作.如果我已经取消订阅,我不知道为什么它还在尝试读取数据.
constructor(private afAuth: AngularFireAuth, private db: AngularFireDatabase) {
this.user = afAuth.authState;
this.userSub = this.user.subscribe(auth => {
if (auth) {
this.member = db.object('/users/' + auth.uid);
this.dbSub = this.member.subscribe();
}
});
}
logout() {
this.dbSub.unsubscribe();
this.userSub.unsubscribe();
this.afAuth.auth.signOut()
.then(() => this.router.navigateByUrl('/login'));
}
Run Code Online (Sandbox Code Playgroud) observable firebase firebase-realtime-database angularfire2 angular
我正在使用模拟数据和 InMemoryDbService,如英雄之旅示例所示。当我不传递 HttpParams 时,加载数据工作正常。添加参数后,我会收到 500 响应,正文中包含以下错误:{error: "collection.filter is not a function"}我已使用 get 请求中的数据填充表,如下所示:
组件代码:
@Component({
selector: 'app-adapter',
templateUrl: './adapter.component.html',
styleUrls: ['./adapter.component.css']
})
export class AdapterComponent implements OnInit {
dataSource = new MatTableDataSource<Request>();
@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor(private api: BaseServiceApi) {}
ngOnInit() {
this.refresh(); // this works with no params and populates my table
}
refresh(params?) {
this.getRequests(params)
.subscribe(reply => {
this.dataSource.data = reply.payload as Request[];
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
this.pageSize = this.paginator.pageSize;
}
); …Run Code Online (Sandbox Code Playgroud) 我正在尝试采用这样的对象数组
[
{
"id": "uniqueParentId1",
"children": [
{
"childProp1": "test1",
"childProp2": "test3"
}
]
},
{
"id": "uniqueParentId2",
"children": [
{
"childProp1": "somevals",
"childProp2": "other vals"
},
{
"childProp1": "somevals 1",
"childProp2": "other vals 1"
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
并返回所有子项组合而成的数组,每个子对象都有一个附加值,即父项的“ id”。
以上示例,结果。
[
{
"parentId": "uniqueParentId1",
"childProp1": "test1",
"childProp2": "test3"
},
{
"parentId": "uniqueParentId2",
"childProp1": "somevals",
"childProp2": "other vals"
}
{
"parentId": "uniqueParentId2",
"childProp1": "somevals 1",
"childProp2": "other vals 1"
}
]
Run Code Online (Sandbox Code Playgroud)
我只是不确定如何解决这个问题。我熟悉数组的展平和数组。但是我只能在不添加parentId的情况下将输出作为原始子项的数组获得
angular ×2
angularfire2 ×1
arrays ×1
firebase ×1
javascript ×1
lambda ×1
node.js ×1
observable ×1
python ×1