def test(): """Test for DataFrame Stats module""" import os from brothon.utils import file_utils # Open a dataset (relative path) data_dir = file_utils.relative_dir(__file__, 'data') file_path = os.path.join(data_dir, 'g_test_data.csv') dataframe = pd.read_csv(file_path) print(dataframe.head()) # Print out the contingency_table print('\nContingency Table') print(contingency_table(dataframe, 'name', 'status')) # Print out the joint_distribution print('\nJoint Distribution Table') print(joint_distribution(dataframe, 'name', 'status')) # Print out the expected_counts print('\nExpected Counts Table') print(expected_counts(dataframe, 'name', 'status')) # Print out the g_test scores print('\nG-Test Scores') print(g_test_scores(dataframe, 'name', 'status'))
def test(): """Test for BroLogReader Python Class""" # Grab a test file data_path = file_utils.relative_dir(__file__, '../data') # For each file, create the Class and test the reader files = [ 'conn.log', 'dns.log', 'http.log', 'dhcp.log', 'files.log', 'weird.log' ] for bro_log in files: test_path = os.path.join(data_path, bro_log) print('Opening Data File: {:s}'.format(test_path)) reader = BroLogReader(test_path, tail=False) # First with no tailing for line in reader.readrows(): print(line) print('Read with NoTail Test successful!') # Now include tailing (note: as an automated test this needs to timeout quickly) try: from interruptingcow import timeout # Spin up the class tailer = BroLogReader(test_path, tail=True) # Tail the file for 2 seconds and then quit try: with timeout(2, exception=RuntimeError): for line in tailer.readrows(): print(line) except RuntimeError: # InterruptingCow raises a RuntimeError on timeout print('Tailing Test successful!') except ImportError: print('Tailing Test not run, need interruptcow module...')
def test(): """Test for FileTailer Python Class""" # Grab a test file data_path = file_utils.relative_dir(__file__, '../../data') test_path = os.path.join(data_path, 'http.log') print('Opening Data File: {:s}'.format(test_path)) # Create the Class tailer = FileTailer(test_path, tail=False) # First with no tailing for line in tailer.readlines(): print(line) print('Read with NoTail Test successful!') # Now include tailing (note: as an automated test this needs to timeout quickly) try: from interruptingcow import timeout # Spin up the class tailer = FileTailer(test_path) # Tail = True # Tail the file for 2 seconds and then quit try: with timeout(2, exception=RuntimeError): for line in tailer.readlines(): print(line) except RuntimeError: # InterruptingCow raises a RuntimeError on timeout print('Tailing Test successful!') except ImportError: print('Tailing Test not run, need interruptcow module...')
def test(): """Test for DataFrame Stats module""" import os from brothon.utils import file_utils # Open a dataset (relative path) data_dir = file_utils.relative_dir(__file__, 'data') file_path = os.path.join(data_dir, 'g_test_data.csv') dataframe = pd.read_csv(file_path) print(dataframe.head()) # Print out the contingency_table print('\nContingency Table') print(contingency_table(dataframe, 'name', 'status')) # Print out the joint_distribution print('\nJoint Distribution Table') print(joint_distribution(dataframe, 'name', 'status')) # Print out the expected_counts print('\nExpected Counts Table') print(expected_counts(dataframe, 'name', 'status')) # Print out the g_test scores print('\nG-Test Scores') print(g_test_scores(dataframe, 'name', 'status'))
def test(): """Test for FileTailer Python Class""" # Grab a test file data_path = file_utils.relative_dir(__file__, '../../data') test_path = os.path.join(data_path, 'http.log') print('Opening Data File: {:s}'.format(test_path)) # Create the Class tailer = FileTailer(test_path, tail=False) # First with no tailing for line in tailer.readlines(): print(line) print('Read with NoTail Test successful!') # Now include tailing (note: as an automated test this needs to timeout quickly) try: from interruptingcow import timeout # Spin up the class tailer = FileTailer(test_path) # Tail = True # Tail the file for 2 seconds and then quit try: with timeout(2, exception=RuntimeError): for line in tailer.readlines(): print(line) except RuntimeError: # InterruptingCow raises a RuntimeError on timeout print('Tailing Test successful!') except ImportError: print('Tailing Test not run, need interruptcow module...')
def test(): """Test the DirWatcher Class""" watch_path = file_utils.relative_dir(__file__, '../../data') print('Watching Directory: %s' % watch_path) DirWatcher(watch_path, my_callback) # Create a file and then delete it temp_file = os.path.join(watch_path, 'test.tmp') open(temp_file, 'w').close() time.sleep(1) os.remove(temp_file)
def test(): """Test the DirWatcher Class""" watch_path = file_utils.relative_dir(__file__, '../../data') print('Watching Directory: %s' % watch_path) DirWatcher(watch_path, my_callback) # Create a file and then delete it temp_file = os.path.join(watch_path, 'test.tmp') open(temp_file, 'w').close() time.sleep(1) os.remove(temp_file)
def test(): """Test for LiveSimulator Python Class""" # Grab a test file data_path = file_utils.relative_dir(__file__, '../data') test_path = os.path.join(data_path, 'conn.log') print('Opening Data File: {:s}'.format(test_path)) # Create a LiveSimulator reader reader = LiveSimulator(test_path, max_rows=10) for line in reader.readrows(): print(line) print('Read with max_rows Test successful!')
def test(): """Test for BroMultiLogReader Python Class""" from brothon.utils import file_utils # Grab a test file data_path = file_utils.relative_dir(__file__, '../data') # For each file, create the Class and test the reader files = ['http.log.gz', 'dhcp*.log', 'dhcp*.log.gz'] for bro_log in files: test_path = os.path.join(data_path, bro_log) print('Opening Data File: {:s}'.format(test_path)) reader = BroMultiLogReader(test_path) for line in reader.readrows(): print(line) print('Tests successful!')
def test(): """Test for BroLogReader Python Class""" # Grab a test file data_path = file_utils.relative_dir(__file__, '../data') # For each file, create the Class and test the reader files = ['app_stats.log', 'conn.log', 'dhcp.log', 'dns.log', 'files.log', 'ftp.log', 'http.log', 'notice.log', 'smtp.log', 'ssl.log', 'weird.log', 'x509.log'] for bro_log in files: test_path = os.path.join(data_path, bro_log) print('Opening Data File: {:s}'.format(test_path)) reader = BroLogReader(test_path, tail=False) # First with no tailing for line in reader.readrows(): print(line) print('Read with NoTail Test successful!') # Test some of the error conditions reader.field_names = ['good', 'error'] reader.type_converters = [int, lambda x: datetime.datetime.fromtimestamp(float(x))] reader.make_dict([5, '0, .5, .5']) # Now include tailing (note: as an automated test this needs to timeout quickly) try: from interruptingcow import timeout # Spin up the class tailer = BroLogReader(test_path, tail=True) # Tail the file for 2 seconds and then quit try: with timeout(2, exception=RuntimeError): for line in tailer.readrows(): print(line) except RuntimeError: # InterruptingCow raises a RuntimeError on timeout print('Tailing Test successful!') except ImportError: print('Tailing Test not run, need interruptcow module...')