|  | 
|  | 1 | +# | 
|  | 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more | 
|  | 3 | +# contributor license agreements.  See the NOTICE file distributed with | 
|  | 4 | +# this work for additional information regarding copyright ownership. | 
|  | 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 | 
|  | 6 | +# (the "License"); you may not use this file except in compliance with | 
|  | 7 | +# the License.  You may obtain a copy of the License at | 
|  | 8 | +# | 
|  | 9 | +#    http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | +# | 
|  | 11 | +# Unless required by applicable law or agreed to in writing, software | 
|  | 12 | +# distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | +# See the License for the specific language governing permissions and | 
|  | 15 | +# limitations under the License. | 
|  | 16 | +# | 
|  | 17 | + | 
|  | 18 | +""" | 
|  | 19 | +Unit tests for PySpark; additional tests are implemented as doctests in | 
|  | 20 | +individual modules. | 
|  | 21 | +
 | 
|  | 22 | +This file will merged to tests.py. But for now, this file is separated to | 
|  | 23 | +focus to streaming test case | 
|  | 24 | +
 | 
|  | 25 | +""" | 
|  | 26 | +from fileinput import input | 
|  | 27 | +from glob import glob | 
|  | 28 | +import os | 
|  | 29 | +import re | 
|  | 30 | +import shutil | 
|  | 31 | +import subprocess | 
|  | 32 | +import sys | 
|  | 33 | +import tempfile | 
|  | 34 | +import time | 
|  | 35 | +import unittest | 
|  | 36 | +import zipfile | 
|  | 37 | + | 
|  | 38 | +from pyspark.streaming.context import StreamingContext | 
|  | 39 | +from pyspark.streaming.duration import * | 
|  | 40 | + | 
|  | 41 | + | 
|  | 42 | +SPARK_HOME = os.environ["SPARK_HOME"] | 
|  | 43 | + | 
|  | 44 | + | 
|  | 45 | +class PySparkStreamingTestCase(unittest.TestCase): | 
|  | 46 | + | 
|  | 47 | +    def setUp(self): | 
|  | 48 | +        self._old_sys_path = list(sys.path) | 
|  | 49 | +        class_name = self.__class__.__name__ | 
|  | 50 | +        self.ssc = StreamingContext(appName=class_name, duration=Seconds(1)) | 
|  | 51 | + | 
|  | 52 | +    def tearDown(self): | 
|  | 53 | +        self.ssc.stop() | 
|  | 54 | +        sys.path = self._old_sys_path | 
|  | 55 | + | 
|  | 56 | + | 
|  | 57 | +if __name__ == "__main__": | 
|  | 58 | +    unittest.main() | 
0 commit comments