Skip to content

Commit

Permalink
style: reformat test code
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed May 2, 2020
1 parent 4160994 commit da8e7e4
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 36 deletions.
5 changes: 3 additions & 2 deletions tests/executors/crafters/image/test_crop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest

import numpy as np

from jina.executors.crafters.image.crop import ImageCropper, CenterImageCropper, RandomImageCropper, FiveImageCropper, \
Expand All @@ -17,11 +18,11 @@ def test_crop(self):
crafter = ImageCropper(left, top, width, height)
crafted_chunk = crafter.craft(img_array, 0, 0)
np.testing.assert_array_equal(
crafted_chunk['blob'], np.asarray(img_array[top:top+height, left:left+width, :]),
crafted_chunk['blob'], np.asarray(img_array[top:top + height, left:left + width, :]),
'img_array: {}\ntest: {}\ncontrol:{}'.format(
img_array.shape,
crafted_chunk['blob'].shape,
np.asarray(img_array[left:left+width, top:top+height, :]).shape))
np.asarray(img_array[left:left + width, top:top + height, :]).shape))

def test_center_crop(self):
img_size = 217
Expand Down
4 changes: 3 additions & 1 deletion tests/executors/crafters/nlp/split.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from tests import JinaTestCase

from jina.executors.crafters.nlp.split import Sentencizer, JiebaSegmenter
from tests import JinaTestCase


class MyTestCase(JinaTestCase):
Expand All @@ -22,5 +23,6 @@ def test_jieba_crafter(self):
crafted_chunk_list = jieba_crafter.craft(raw_bytes, 0)
self.assertEqual(len(crafted_chunk_list), 14)


if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/executors/encoders/image/test_onnx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
import os

from jina.executors.encoders.image.onnx import OnnxImageEncoder
from . import ImageTestCase
Expand Down
1 change: 0 additions & 1 deletion tests/executors/encoders/nlp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np

from jina.executors import BaseExecutor
from jina.executors.encoders.nlp.paddlehub import TextPaddlehubEncoder
from tests import JinaTestCase


Expand Down
5 changes: 3 additions & 2 deletions tests/executors/encoders/numeric/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import os

from tests import JinaTestCase
import numpy as np

from jina.executors import BaseExecutor
from tests import JinaTestCase


class NumericTestCase(JinaTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/executors/encoders/numeric/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np

from . import NumericTestCase
from jina.executors.encoders.numeric.pca import IncrementalPCAEncoder
from . import NumericTestCase


class MyTestCase(NumericTestCase):
Expand Down
10 changes: 6 additions & 4 deletions tests/executors/indexers/keyvalue/test_leveldb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest
import os
from tests import JinaTestCase
from jina.executors.indexers.keyvalue.leveldb import LeveldbIndexer
import unittest

from google.protobuf.json_format import MessageToJson

import jina.proto.jina_pb2 as jina_pb2
from jina.executors.indexers import BaseIndexer
from google.protobuf.json_format import MessageToJson
from jina.executors.indexers.keyvalue.leveldb import LeveldbIndexer
from tests import JinaTestCase


class MyTestCase(JinaTestCase):
Expand Down
1 change: 1 addition & 0 deletions tests/executors/indexers/vector/test_annoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest

import numpy as np

from jina.executors.indexers import BaseIndexer
from jina.executors.indexers.vector.annoy import AnnoyIndexer
from jina.executors.indexers.vector.nmslib import NmslibIndexer
Expand Down
1 change: 0 additions & 1 deletion tests/executors/rankers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ def test_ranker(self):
self.assertEqual(doc_idx[1][0], 4294967294)
# check the number of matched docs
self.assertEqual(len(doc_idx), 2)

2 changes: 0 additions & 2 deletions tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def random_docs(num_docs, chunks_per_doc=5, embed_dim=10):
built = False
img_name = 'jina/mwu-encoder'


defaulthost = '0.0.0.0'
localhost = defaulthost if (platform == "linux" or platform == "linux2") else 'host.docker.internal'

Expand All @@ -44,7 +43,6 @@ def build_image():
# @unittest.skipUnless(os.getenv('JINA_TEST_CONTAINER', False), 'skip the container test if not set')
class MyTestCase(JinaTestCase):


def tearDown(self) -> None:
super().tearDown()
time.sleep(2)
Expand Down
12 changes: 0 additions & 12 deletions tests/test_flow.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import unittest

import requests
from jina import JINA_GLOBAL
from jina.enums import FlowOptimizeLevel
from jina.flow import Flow
from jina.main.checker import NetworkChecker
from jina.main.parser import set_pea_parser, set_ping_parser
from jina.main.parser import set_pod_parser
from jina.peapods.pea import BasePea
from jina.peapods.pod import BasePod
from jina.proto import jina_pb2
from tests import JinaTestCase
import unittest

import requests
from jina import JINA_GLOBAL
from jina.enums import FlowOptimizeLevel
from jina.flow import Flow
Expand Down
1 change: 1 addition & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np

from jina.drivers.helper import array2pb
from jina.enums import FlowOptimizeLevel
from jina.executors.indexers.vector.numpy import NumpyIndexer
Expand Down
1 change: 1 addition & 0 deletions tests/test_index_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np

from jina.drivers.helper import array2pb
from jina.enums import FlowOptimizeLevel
from jina.executors.indexers.vector.numpy import NumpyIndexer
Expand Down
9 changes: 0 additions & 9 deletions tests/test_loadbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
import time

import numpy as np
from jina.drivers.helper import array2pb
from jina.enums import SchedulerType
from jina.executors.crafters import BaseDocCrafter
from jina.flow import Flow
from jina.proto import jina_pb2
from tests import JinaTestCase
import os
import time

import numpy as np
from jina.drivers.helper import array2pb
from jina.enums import SchedulerType
from jina.executors.crafters import BaseDocCrafter
Expand Down
11 changes: 11 additions & 0 deletions tests/test_quant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import numpy as np

from jina.drivers.helper import array2pb, pb2array
from jina.flow import Flow
from jina.proto import jina_pb2
Expand Down Expand Up @@ -52,6 +53,16 @@ def f1(self, quant):
with f as fl:
fl.index(random_docs, output_fn=get_output, in_proto=True)

def f2(self, quant):
os.environ['JINA_ARRAY_QUANT'] = quant

f = Flow(callback_on_body=True, compress_hwm=1024).add(yaml_path='_forward').add(yaml_path='_forward').add(
yaml_path='_forward').add(
yaml_path='_forward').add(yaml_path='_forward').add(yaml_path='_forward').add(yaml_path='_forward')
with f as fl:
fl.index(random_docs, output_fn=get_output, in_proto=True)

def test_quant(self):
for j in ('fp32', 'fp16', 'uint8'):
self.f1(j)
self.f2(j)

0 comments on commit da8e7e4

Please sign in to comment.