def test_parse_file_compressed(): """Test line parser on 'test/test.log.gz'.""" stats = reican.Stats(test_file_name_compressed) stats = reican.parse_file(test_file_name_compressed, stats) assert isinstance(stats, reican.Stats) assert stats.size == test_file_name_compressed_size assert len(stats.lines) == 3 assert stats.compressed
def test_analyze_stats_2(): """Test analyze_stats() with test/minidlna.""" stats = reican.Stats(test_file_name2) stats = reican.parse_file(test_file_name2, stats) stats = reican.analyze_stats(stats) times = stats.times assert stats.analyzed is True assert times['delta'].total_seconds() == 2833499.0 assert stats.bytes_per_line == 101 assert len(stats.per_hour_aggregation) == 11 assert isinstance(stats.aggregation[2017], dict) assert stats.aggregation[2017][3][25][18] == 2
def test_analyze_stats_1(): """Test analyze_stats() with test/test.log.""" stats = reican.Stats(test_file_name) stats = reican.parse_file(test_file_name, stats) stats = reican.analyze_stats(stats) times = stats.times assert stats.analyzed is True assert times['delta'].total_seconds() == 15290.159069 assert stats.bytes_per_line == 73 assert len(stats.per_hour_aggregation) == 3 assert isinstance(stats.aggregation[2015], dict) assert stats.aggregation[2015][10][31][10] == 1
def test_stats_line_increment(): s = reican.Stats(test_file_name) s.increment_line_counter() assert s.line_counter == 1
def test_stats(): s = reican.Stats(test_file_name) assert isinstance(s, types.InstanceType)
missing_test_file_name = "test/test_missing.log" test_file_name_size = 221 test_file_name2_size = 221 test_file_name_compressed_size = 44 # def test_get_size(): # def mockreturn(argv): # return ("stuff") # import os # patch = os.stat("test/test.log") # monkeypatch.setattr('patch.st_size', mockreturn) # print reican.get_size("test/test.log") stats = reican.Stats(test_file_name) def test_die_1(): """Test the die() function.""" with pytest.raises(SystemExit): reican.die() def test_die_2(capsys): """Test die() with optional argument.""" with pytest.raises(SystemExit): reican.die("Something") out, err = capsys.readouterr() assert out == "\nSomething\n\n"