11#!/usr/bin/env python
2- # coding: utf-8
2+ # -*- coding: utf-8 -*-
33
44import os
55import sys
66import json
77import unittest
88
9- from io import open
109from cortexutils .analyzer import Analyzer
1110
12- # Different lib when using python3 or 2
13- if sys .version_info >= (3 , 0 ):
14- from io import StringIO
15- else :
16- from StringIO import StringIO
11+ from io import StringIO
1712
1813
1914def load_test_fixture (fixture_path ):
20- path = os .path .dirname (os .path .abspath (__file__ ))
21- fixture_file = open ( path + "/" + fixture_path )
22- input = fixture_file . read ()
23- fixture_file .close ()
15+ tests_dir = os .path .dirname (os .path .abspath (__file__ ))
16+ file_path = os . path . join ( tests_dir , fixture_path )
17+ with open ( file_path ) as fixture_file :
18+ input = fixture_file .read ()
2419 sys .stdin = StringIO (input )
2520 sys .stdout = StringIO ()
2621
2722
2823class TestMinimalConfig (unittest .TestCase ):
2924 def setUp (self ):
30- load_test_fixture ("fixtures/test-minimal-config.json" )
25+ fixture_path = os .path .join ("fixtures" , "test-minimal-config.json" )
26+ load_test_fixture (fixture_path )
3127 self .analyzer = Analyzer ()
3228
3329 def test_default_config (self ):
@@ -49,7 +45,8 @@ def test_params_data(self):
4945
5046class TestProxyConfig (unittest .TestCase ):
5147 def setUp (self ):
52- load_test_fixture ("fixtures/test-proxy-config.json" )
48+ fixture_path = os .path .join ("fixtures" , "test-proxy-config.json" )
49+ load_test_fixture (fixture_path )
5350 self .analyzer = Analyzer ()
5451
5552 def test_proxy_config (self ):
@@ -64,7 +61,8 @@ def test_proxy_config(self):
6461
6562class TestTlpConfig (unittest .TestCase ):
6663 def setUp (self ):
67- load_test_fixture ("fixtures/test-tlp-config.json" )
64+ fixture_path = os .path .join ("fixtures" , "test-tlp-config.json" )
65+ load_test_fixture (fixture_path )
6866 self .analyzer = Analyzer ()
6967
7068 def test_check_tlp_disabled (self ):
@@ -95,7 +93,8 @@ def test_check_tlp_ok(self):
9593
9694class TestErrorResponse (unittest .TestCase ):
9795 def setUp (self ):
98- load_test_fixture ("fixtures/test-error-response.json" )
96+ fixture_path = os .path .join ("fixtures" , "test-error-response.json" )
97+ load_test_fixture (fixture_path )
9998 self .analyzer = Analyzer ()
10099
101100 def test_error_response (self ):
@@ -130,7 +129,8 @@ def test_error_response(self):
130129
131130class TestReportResponse (unittest .TestCase ):
132131 def setUp (self ):
133- load_test_fixture ("fixtures/test-report-response.json" )
132+ fixture_path = os .path .join ("fixtures" , "test-report-response.json" )
133+ load_test_fixture (fixture_path )
134134 self .analyzer = Analyzer ()
135135
136136 def test_report_response (self ):
0 commit comments