Skip to content

Commit

Permalink
refactor unittest structure v2
Browse files Browse the repository at this point in the history
  • Loading branch information
congee524 committed Dec 16, 2020
1 parent 0c664e5 commit fede29c
Show file tree
Hide file tree
Showing 71 changed files with 699 additions and 1,044 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/data/annotations/frame_list.txt

This file was deleted.

2 changes: 0 additions & 2 deletions tests/data/annotations/frame_list_multi_label.txt

This file was deleted.

2 changes: 0 additions & 2 deletions tests/data/annotations/frame_list_with_offset.txt

This file was deleted.

2 changes: 2 additions & 0 deletions tests/data/annotations/frame_test_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imgs 5 127
imgs 5 127
2 changes: 2 additions & 0 deletions tests/data/annotations/frame_test_list_multi_label.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imgs 5 1
imgs 5 3 5
2 changes: 2 additions & 0 deletions tests/data/annotations/frame_test_list_with_offset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imgs 2 5 127
imgs 2 5 127
24 changes: 0 additions & 24 deletions tests/data/annotations/hvu_frame_anno.json

This file was deleted.

58 changes: 58 additions & 0 deletions tests/data/annotations/hvu_frame_test_anno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"frame_dir": "imgs",
"total_frames": 5,
"label": {
"concept": [
250,
131,
42,
51,
57,
155,
122
],
"object": [
1570,
508
],
"event": [
16
],
"action": [
180
],
"scene": [
206
]
}
},
{
"frame_dir": "imgs",
"total_frames": 5,
"label": {
"concept": [
250,
131,
42,
51,
57,
155,
122
],
"object": [
1570,
508
],
"event": [
16
],
"action": [
180
],
"scene": [
206
]
}
}
]
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/data/annotations/proposal_normalized_list.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 0
test_imgs
imgs
5
1
2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 0
test_imgs
imgs
5
1
2
Expand Down
8 changes: 0 additions & 8 deletions tests/data/annotations/rawvideo_anno.json

This file was deleted.

1 change: 0 additions & 1 deletion tests/data/annotations/rawvideo_anno.txt

This file was deleted.

10 changes: 10 additions & 0 deletions tests/data/annotations/rawvideo_test_anno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"video_dir": "rawvideo_dataset",
"label": 1,
"num_clips": 2,
"positive_clip_inds": [
0
]
}
]
1 change: 1 addition & 0 deletions tests/data/annotations/rawvideo_test_anno.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawvideo_dataset 1 2 0
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/test_data/test_datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .base import BaseTestDataset

__all__ = ['BaseTestDataset']
36 changes: 20 additions & 16 deletions tests/test_data/test_datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mmcv import ConfigDict


class TestDataset:
class BaseTestDataset:

@staticmethod
def check_keys_contain(result_keys, target_keys):
Expand All @@ -14,34 +14,38 @@ def check_keys_contain(result_keys, target_keys):
def setup_class(cls):
# prefix path
cls.data_prefix = osp.normpath(
osp.join(osp.dirname(__file__), '../data'))
osp.join(osp.dirname(__file__), '../../data'))
cls.ann_file_prefix = osp.join(cls.data_prefix, 'annotations')

# annotations path
cls.action_ann_file = osp.join(cls.ann_file_prefix, 'action_anno.json')
cls.action_ann_file = osp.join(cls.ann_file_prefix,
'action_test_anno.json')
cls.audio_feature_ann_file = osp.join(cls.ann_file_prefix,
'audio_feature_list.txt')
cls.audio_ann_file = osp.join(cls.ann_file_prefix, 'audio_list.txt')
'audio_feature_test_list.txt')
cls.audio_ann_file = osp.join(cls.ann_file_prefix,
'audio_test_list.txt')
cls.frame_ann_file_multi_label = osp.join(
cls.ann_file_prefix, 'frame_list_multi_label.txt')
cls.ann_file_prefix, 'frame_test_list_multi_label.txt')
cls.frame_ann_file_with_offset = osp.join(
cls.ann_file_prefix, 'frame_list_with_offset.txt')
cls.frame_ann_file = osp.join(cls.ann_file_prefix, 'frame_list.txt')
cls.ann_file_prefix, 'frame_test_list_with_offset.txt')
cls.frame_ann_file = osp.join(cls.ann_file_prefix,
'frame_test_list.txt')
cls.hvu_frame_ann_file = osp.join(cls.ann_file_prefix,
'hvu_frame_anno.json')
'hvu_frame_test_anno.json')
cls.hvu_video_ann_file = osp.join(cls.ann_file_prefix,
'hvu_video_anno.json')
cls.hvu_video_eval_ann_file = osp.join(cls.ann_file_prefix,
'hvu_video_eval_anno.json')
'hvu_video_test_anno.json')
cls.hvu_video_eval_ann_file = osp.join(
cls.ann_file_prefix, 'hvu_video_eval_test_anno.json')
cls.proposal_ann_file = osp.join(cls.ann_file_prefix,
'proposal_list.txt')
'proposal_test_list.txt')
cls.proposal_norm_ann_file = osp.join(cls.ann_file_prefix,
'proposal_normalized_list.txt')
cls.rawvideo_test_anno_json = osp.join(cls.ann_file_prefix,
'rawvideo_anno.json')
'rawvideo_test_anno.json')
cls.rawvideo_test_anno_txt = osp.join(cls.ann_file_prefix,
'rawvideo_anno.txt')
cls.video_ann_file = osp.join(cls.ann_file_prefix, 'video_list.txt')
'rawvideo_test_anno.txt')
cls.video_ann_file = osp.join(cls.ann_file_prefix,
'video_test_list.txt')

# pipeline configuration
cls.action_pipeline = []
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data/test_datasets/test_activitynet_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from numpy.testing import assert_array_equal

from mmaction.datasets import ActivityNetDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestActivitynetDataset(TestDataset):
class TestActivitynetDataset(BaseTestDataset):

def test_activitynet_dataset(self):
activitynet_dataset = ActivityNetDataset(self.action_ann_file,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data/test_datasets/test_audio_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pytest

from mmaction.datasets import AudioDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestAudioDataset(TestDataset):
class TestAudioDataset(BaseTestDataset):

def test_audio_dataset(self):
audio_dataset = AudioDataset(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data/test_datasets/test_audio_feature_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pytest

from mmaction.datasets import AudioFeatureDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestAudioFeatureDataset(TestDataset):
class TestAudioFeatureDataset(BaseTestDataset):

def test_audio_feature_dataset(self):
audio_dataset = AudioFeatureDataset(
Expand Down
10 changes: 5 additions & 5 deletions tests/test_data/test_datasets/test_audio_visual_dataset.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os.path as osp

from mmaction.datasets import AudioVisualDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestAudioVisualDataset(TestDataset):
class TestAudioVisualDataset(BaseTestDataset):

def test_audio_visual_dataset(self):
test_dataset = AudioVisualDataset(
Expand All @@ -14,9 +14,9 @@ def test_audio_visual_dataset(self):
video_prefix=self.data_prefix,
data_prefix=self.data_prefix)
video_infos = test_dataset.video_infos
frame_dir = osp.join(self.data_prefix, 'test_imgs')
audio_path = osp.join(self.data_prefix, 'test_imgs.npy')
filename = osp.join(self.data_prefix, 'test_imgs.mp4')
frame_dir = osp.join(self.data_prefix, 'imgs')
audio_path = osp.join(self.data_prefix, 'imgs.npy')
filename = osp.join(self.data_prefix, 'imgs.mp4')
assert video_infos == [
dict(
frame_dir=frame_dir,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_data/test_datasets/test_ava_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from numpy.testing import assert_array_equal

from mmaction.datasets import AVADataset
from .base import TestDataset
from .base import BaseTestDataset


class TestAVADataset(TestDataset):
class TestAVADataset(BaseTestDataset):

@classmethod
def setup_class(cls):
cls.data_prefix = osp.normpath(
osp.join(osp.dirname(__file__), '../../data', 'test_ava_dataset'))
osp.join(osp.dirname(__file__), '../../data', 'ava_dataset'))
cls.ann_file = osp.join(cls.data_prefix, 'ava_sample.csv')
cls.exclude_file = osp.join(cls.data_prefix,
'ava_excluded_timestamps_sample.csv')
Expand Down
6 changes: 3 additions & 3 deletions tests/test_data/test_datasets/test_hvu_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from numpy.testing import assert_array_almost_equal

from mmaction.datasets import HVUDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestHVUDataset(TestDataset):
class TestHVUDataset(BaseTestDataset):

def test_hvu_dataset(self):
hvu_frame_dataset = HVUDataset(
Expand All @@ -19,7 +19,7 @@ def test_hvu_dataset(self):
data_prefix=self.data_prefix,
start_index=1)
hvu_frame_infos = hvu_frame_dataset.video_infos
frame_dir = osp.join(self.data_prefix, 'test_imgs')
frame_dir = osp.join(self.data_prefix, 'imgs')
assert hvu_frame_infos == [
dict(
frame_dir=frame_dir,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_data/test_datasets/test_rawframe_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import pytest

from mmaction.datasets import RawframeDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestRawframDataset(TestDataset):
class TestRawframDataset(BaseTestDataset):

def test_rawframe_dataset(self):
rawframe_dataset = RawframeDataset(self.frame_ann_file,
self.frame_pipeline,
self.data_prefix)
rawframe_infos = rawframe_dataset.video_infos
frame_dir = osp.join(self.data_prefix, 'test_imgs')
frame_dir = osp.join(self.data_prefix, 'imgs')
assert rawframe_infos == [
dict(frame_dir=frame_dir, total_frames=5, label=127)
] * 2
Expand All @@ -27,7 +27,7 @@ def test_rawframe_dataset_with_offset(self):
self.data_prefix,
with_offset=True)
rawframe_infos = rawframe_dataset.video_infos
frame_dir = osp.join(self.data_prefix, 'test_imgs')
frame_dir = osp.join(self.data_prefix, 'imgs')
assert rawframe_infos == [
dict(frame_dir=frame_dir, offset=2, total_frames=5, label=127)
] * 2
Expand All @@ -41,7 +41,7 @@ def test_rawframe_dataset_multi_label(self):
multi_class=True,
num_classes=100)
rawframe_infos = rawframe_dataset.video_infos
frame_dir = osp.join(self.data_prefix, 'test_imgs')
frame_dir = osp.join(self.data_prefix, 'imgs')
label0 = [1]
label1 = [3, 5]
labels = [label0, label1]
Expand All @@ -61,7 +61,7 @@ def test_dataset_realpath(self):

dataset = RawframeDataset(self.frame_ann_file, self.frame_pipeline)
assert dataset.data_prefix is None
assert dataset.video_infos[0]['frame_dir'] == 'test_imgs'
assert dataset.video_infos[0]['frame_dir'] == 'imgs'

def test_rawframe_pipeline(self):
target_keys = [
Expand Down
7 changes: 3 additions & 4 deletions tests/test_data/test_datasets/test_rawvideo_dataset.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os.path as osp

from mmaction.datasets import RawVideoDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestRawVideoDataset(TestDataset):
class TestRawVideoDataset(BaseTestDataset):

def test_rawvideo_dataset(self):
# Try to load txt file
Expand All @@ -15,8 +15,7 @@ def test_rawvideo_dataset(self):
sampling_strategy='positive',
data_prefix=self.data_prefix)
result = rawvideo_dataset[0]
clipname = osp.join(self.data_prefix, 'test_rawvideo_dataset',
'part_0.mp4')
clipname = osp.join(self.data_prefix, 'rawvideo_dataset', 'part_0.mp4')
assert result['filename'] == clipname

# Try to load json file
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data/test_datasets/test_repeat_dataset.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

from mmaction.datasets import RawframeDataset, RepeatDataset
from .base import TestDataset
from .base import BaseTestDataset


class TestRepeatDataset(TestDataset):
class TestRepeatDataset(BaseTestDataset):

def test_repeat_dataset(self):
rawframe_dataset = RawframeDataset(self.frame_ann_file,
Expand Down
Loading

0 comments on commit fede29c

Please sign in to comment.