From f7766054dc778d0ee51af78d407633acdb6b895f Mon Sep 17 00:00:00 2001 From: Giuseppe Valente Date: Thu, 16 Mar 2017 16:57:03 -0700 Subject: [PATCH 1/4] filebeat: fix pylint in test_registrar --- filebeat/tests/system/test_registrar.py | 426 ++++++++++++------------ 1 file changed, 217 insertions(+), 209 deletions(-) diff --git a/filebeat/tests/system/test_registrar.py b/filebeat/tests/system/test_registrar.py index 989fc4834919..3ed745662740 100644 --- a/filebeat/tests/system/test_registrar.py +++ b/filebeat/tests/system/test_registrar.py @@ -1,12 +1,11 @@ -from filebeat import BaseTest +"""Test the registrar""" # pylint: disable=too-many-lines import os import platform import time import shutil -import json -import stat -from nose.plugins.skip import Skip, SkipTest +from filebeat import BaseTest +from nose.plugins.skip import SkipTest # Additional tests: to be implemented @@ -15,11 +14,11 @@ # * Check what happens when registrar file is deleted -class Test(BaseTest): +class Test(BaseTest): # pylint: disable=too-many-public-methods + """Test class""" def test_registrar_file_content(self): - """ - Check if registrar file is created correctly and content is as expected + """Check if registrar file is created correctly and content is as expected """ self.render_config_template( @@ -31,13 +30,13 @@ def test_registrar_file_content(self): line = "hello world\n" line_len = len(line) - 1 + len(os.linesep) iterations = 5 - testfile = self.working_dir + "/log/test.log" - file = open(testfile, 'w') - file.write(iterations * line) - file.close() + testfile_path = self.working_dir + "/log/test.log" + testfile = open(testfile_path, 'w') + testfile.write(iterations * line) + testfile.close() filebeat = self.start_beat() - c = self.log_contains_count("states written") + count = self.log_contains_count("states written") self.wait_until( lambda: self.output_has(lines=5), @@ -45,7 +44,7 @@ def test_registrar_file_content(self): # Make sure states written appears one more time self.wait_until( - lambda: self.log_contains("states written") > c, + lambda: self.log_contains("states written") > count, max_timeout=10) # wait until the registry file exist. Needed to avoid a race between @@ -60,11 +59,11 @@ def test_registrar_file_content(self): data = self.get_registry() assert len(data) == 1 - logFileAbsPath = os.path.abspath(testfile) - record = self.get_registry_entry_by_path(logFileAbsPath) + logfile_abs_path = os.path.abspath(testfile_path) + record = self.get_registry_entry_by_path(logfile_abs_path) self.assertDictContainsSubset({ - "source": logFileAbsPath, + "source": logfile_abs_path, "offset": iterations * line_len, }, record) self.assertTrue("FileStateOS" in record) @@ -75,14 +74,14 @@ def test_registrar_file_content(self): # TODO: Check for IdxHi, IdxLo, Vol in FileStateOS on Windows. self.assertEqual(len(file_state_os), 3) elif platform.system() == "SunOS": - stat = os.stat(logFileAbsPath) + stat = os.stat(logfile_abs_path) self.assertEqual(file_state_os["inode"], stat.st_ino) # Python does not return the same st_dev value as Golang or the # command line stat tool so just check that it's present. self.assertTrue("device" in file_state_os) else: - stat = os.stat(logFileAbsPath) + stat = os.stat(logfile_abs_path) self.assertDictContainsSubset({ "inode": stat.st_ino, "device": stat.st_dev, @@ -98,13 +97,13 @@ def test_registrar_files(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/test1.log" - testfile2 = self.working_dir + "/log/test2.log" - file1 = open(testfile1, 'w') - file2 = open(testfile2, 'w') + testfile_path1 = self.working_dir + "/log/test1.log" + testfile_path2 = self.working_dir + "/log/test2.log" + file1 = open(testfile_path1, 'w') + file2 = open(testfile_path2, 'w') iterations = 5 - for n in range(0, iterations): + for _ in range(0, iterations): file1.write("hello world") # 11 chars file1.write("\n") # 1 char file2.write("goodbye world") # 11 chars @@ -132,7 +131,7 @@ def test_registrar_files(self): # Check that 2 files are port of the registrar file assert len(data) == 2 - def test_custom_registry_file_location(self): + def test_custom_registry_file_location(self): # pylint: disable=invalid-name """ Check that when a custom registry file is used, the path is created automatically. @@ -142,9 +141,9 @@ def test_custom_registry_file_location(self): registryFile="a/b/c/registry", ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" - with open(testfile, 'w') as f: - f.write("hello world\n") + testfile_path = self.working_dir + "/log/test.log" + with open(testfile_path, 'w') as testfile: + testfile.write("hello world\n") filebeat = self.start_beat() self.wait_until( lambda: self.output_has(lines=1), @@ -170,21 +169,21 @@ def test_rotating_file(self): ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" + testfile_path = self.working_dir + "/log/test.log" filebeat = self.start_beat() - with open(testfile, 'w') as f: - f.write("offset 9\n") + with open(testfile_path, 'w') as testfile: + testfile.write("offset 9\n") self.wait_until(lambda: self.output_has(lines=1), max_timeout=10) testfilerenamed = self.working_dir + "/log/test.1.log" - os.rename(testfile, testfilerenamed) + os.rename(testfile_path, testfilerenamed) - with open(testfile, 'w') as f: - f.write("offset 10\n") + with open(testfile_path, 'w') as testfile: + testfile.write("offset 10\n") self.wait_until(lambda: self.output_has(lines=2), max_timeout=10) @@ -204,10 +203,10 @@ def test_rotating_file(self): # Make sure the offsets are correctly set if os.name == "nt": - assert self.get_registry_entry_by_path(os.path.abspath(testfile))["offset"] == 11 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path))["offset"] == 11 assert self.get_registry_entry_by_path(os.path.abspath(testfilerenamed))["offset"] == 10 else: - assert self.get_registry_entry_by_path(os.path.abspath(testfile))["offset"] == 10 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path))["offset"] == 10 assert self.get_registry_entry_by_path(os.path.abspath(testfilerenamed))["offset"] == 9 # Check that 2 files are port of the registrar file @@ -222,8 +221,8 @@ def test_data_path(self): path_data=self.working_dir + "/datapath", skip_registry_config=True, ) - with open(self.working_dir + "/test.log", "w") as f: - f.write("test message\n") + with open(self.working_dir + "/test.log", "w") as testfile: + testfile.write("test message\n") filebeat = self.start_beat() self.wait_until(lambda: self.output_has(lines=1)) filebeat.check_kill_and_wait() @@ -244,26 +243,26 @@ def test_rotating_file_inode(self): raise SkipTest os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/input" + testfile_path = self.working_dir + "/log/input" filebeat = self.start_beat() - with open(testfile, 'w') as f: - f.write("entry1\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry1\n") self.wait_until( lambda: self.output_has(lines=1), max_timeout=10) data = self.get_registry() - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] testfilerenamed1 = self.working_dir + "/log/input.1" - os.rename(testfile, testfilerenamed1) + os.rename(testfile_path, testfilerenamed1) - with open(testfile, 'w') as f: - f.write("entry2\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry2\n") self.wait_until( lambda: self.output_has(lines=2), @@ -279,23 +278,23 @@ def test_rotating_file_inode(self): data = self.get_registry() - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] assert os.stat(testfilerenamed1).st_ino == self.get_registry_entry_by_path( os.path.abspath(testfilerenamed1))["FileStateOS"]["inode"] # Rotate log file, create a new empty one and remove it afterwards testfilerenamed2 = self.working_dir + "/log/input.2" os.rename(testfilerenamed1, testfilerenamed2) - os.rename(testfile, testfilerenamed1) + os.rename(testfile_path, testfilerenamed1) - with open(testfile, 'w') as f: - f.write("") + with open(testfile_path, 'w') as testfile: + testfile.write("") os.remove(testfilerenamed2) - with open(testfile, 'w') as f: - f.write("entry3\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry3\n") self.wait_until( lambda: self.output_has(lines=3), @@ -306,8 +305,8 @@ def test_rotating_file_inode(self): data = self.get_registry() # Compare file inodes and the one in the registry - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] assert os.stat(testfilerenamed1).st_ino == self.get_registry_entry_by_path( os.path.abspath(testfilerenamed1))["FileStateOS"]["inode"] @@ -328,12 +327,12 @@ def test_restart_continue(self): raise SkipTest os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/input" + testfile_path = self.working_dir + "/log/input" filebeat = self.start_beat() - with open(testfile, 'w') as f: - f.write("entry1\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry1\n") self.wait_until( lambda: self.output_has(lines=1), @@ -342,8 +341,8 @@ def test_restart_continue(self): # Wait a momemt to make sure registry is completely written time.sleep(1) - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] filebeat.check_kill_and_wait() @@ -351,8 +350,8 @@ def test_restart_continue(self): shutil.copyfile(self.working_dir + "/registry", self.working_dir + "/registry.first") # Append file - with open(testfile, 'a') as f: - f.write("entry2\n") + with open(testfile_path, 'a') as testfile: + testfile.write("entry2\n") filebeat = self.start_beat(output="filebeat2.log") @@ -370,16 +369,17 @@ def test_restart_continue(self): data = self.get_registry() # Compare file inodes and the one in the registry - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] - # Check that 1 files are part of the registrar file. The deleted file should never have been detected + # Check that 1 files are part of the registrar file. The deleted file + # should never have been detected assert len(data) == 1 output = self.read_output() # Check that output file has the same number of lines as the log file - assert 1 == len(output) + assert len(output) == 1 assert output[0]["message"] == "entry2" def test_rotating_file_with_restart(self): @@ -396,12 +396,12 @@ def test_rotating_file_with_restart(self): raise SkipTest os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/input" + testfile_path = self.working_dir + "/log/input" filebeat = self.start_beat() - with open(testfile, 'w') as f: - f.write("entry1\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry1\n") self.wait_until( lambda: self.output_has(lines=1), @@ -411,14 +411,14 @@ def test_rotating_file_with_restart(self): time.sleep(1) data = self.get_registry() - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] testfilerenamed1 = self.working_dir + "/log/input.1" - os.rename(testfile, testfilerenamed1) + os.rename(testfile_path, testfilerenamed1) - with open(testfile, 'w') as f: - f.write("entry2\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry2\n") self.wait_until( lambda: self.output_has(lines=2), @@ -435,8 +435,8 @@ def test_rotating_file_with_restart(self): data = self.get_registry() - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] assert os.stat(testfilerenamed1).st_ino == self.get_registry_entry_by_path( os.path.abspath(testfilerenamed1))["FileStateOS"]["inode"] @@ -448,15 +448,15 @@ def test_rotating_file_with_restart(self): # Rotate log file, create a new empty one and remove it afterwards testfilerenamed2 = self.working_dir + "/log/input.2" os.rename(testfilerenamed1, testfilerenamed2) - os.rename(testfile, testfilerenamed1) + os.rename(testfile_path, testfilerenamed1) - with open(testfile, 'w') as f: - f.write("") + with open(testfile_path, 'w') as testfile: + testfile.write("") os.remove(testfilerenamed2) - with open(testfile, 'w') as f: - f.write("entry3\n") + with open(testfile_path, 'w') as testfile: + testfile.write("entry3\n") filebeat = self.start_beat(output="filebeat2.log") @@ -474,8 +474,8 @@ def test_rotating_file_with_restart(self): data = self.get_registry() # Compare file inodes and the one in the registry - assert os.stat(testfile).st_ino == self.get_registry_entry_by_path( - os.path.abspath(testfile))["FileStateOS"]["inode"] + assert os.stat(testfile_path).st_ino == self.get_registry_entry_by_path( + os.path.abspath(testfile_path))["FileStateOS"]["inode"] assert os.stat(testfilerenamed1).st_ino == self.get_registry_entry_by_path( os.path.abspath(testfilerenamed1))["FileStateOS"]["inode"] @@ -495,15 +495,15 @@ def test_state_after_rotation(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/input" - testfile2 = self.working_dir + "/log/input.1" - testfile3 = self.working_dir + "/log/input.2" + testfile_path1 = self.working_dir + "/log/input" + testfile_path2 = self.working_dir + "/log/input.1" + testfile_path3 = self.working_dir + "/log/input.2" - with open(testfile1, 'w') as f: - f.write("entry10\n") + with open(testfile_path1, 'w') as testfile: + testfile.write("entry10\n") - with open(testfile2, 'w') as f: - f.write("entry0\n") + with open(testfile_path2, 'w') as testfile: + testfile.write("entry0\n") filebeat = self.start_beat() @@ -513,26 +513,26 @@ def test_state_after_rotation(self): # Wait a moment to make sure file exists time.sleep(1) - data = self.get_registry() + self.get_registry() # Check that offsets are correct if os.name == "nt": # Under windows offset is +1 because of additional newline char - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 9 - assert self.get_registry_entry_by_path(os.path.abspath(testfile2))["offset"] == 8 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 9 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 8 else: - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 8 - assert self.get_registry_entry_by_path(os.path.abspath(testfile2))["offset"] == 7 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 8 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 7 # Rotate files and remove old one - os.rename(testfile2, testfile3) - os.rename(testfile1, testfile2) + os.rename(testfile_path2, testfile_path3) + os.rename(testfile_path1, testfile_path2) - with open(testfile1, 'w') as f: - f.write("entry200\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("entry200\n") # Remove file afterwards to make sure not inode reuse happens - os.remove(testfile3) + os.remove(testfile_path3) # Now wait until rotation is detected self.wait_until( @@ -551,13 +551,13 @@ def test_state_after_rotation(self): # Check that offsets are correct if os.name == "nt": # Under windows offset is +1 because of additional newline char - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 10 - assert self.get_registry_entry_by_path(os.path.abspath(testfile2))["offset"] == 9 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 10 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 9 else: - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 9 - assert self.get_registry_entry_by_path(os.path.abspath(testfile2))["offset"] == 8 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 9 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 8 - def test_state_after_rotation_ignore_older(self): + def test_state_after_rotation_ignore_older(self): # pylint: disable=invalid-name """ Checks that the state is written correctly after rotation and ignore older """ @@ -569,19 +569,19 @@ def test_state_after_rotation_ignore_older(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/input" - testfile2 = self.working_dir + "/log/input.1" - testfile3 = self.working_dir + "/log/input.2" + testfile_path1 = self.working_dir + "/log/input" + testfile_path2 = self.working_dir + "/log/input.1" + testfile_path3 = self.working_dir + "/log/input.2" - with open(testfile1, 'w') as f: - f.write("entry10\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("entry10\n") - with open(testfile2, 'w') as f: - f.write("entry0\n") + with open(testfile_path2, 'w') as testfile2: + testfile2.write("entry0\n") # Change modification time so file extends ignore_older yesterday = time.time() - 3600 * 24 - os.utime(testfile2, (yesterday, yesterday)) + os.utime(testfile_path2, (yesterday, yesterday)) filebeat = self.start_beat() @@ -591,24 +591,24 @@ def test_state_after_rotation_ignore_older(self): # Wait a moment to make sure file exists time.sleep(1) - data = self.get_registry() + self.get_registry() # Check that offsets are correct if os.name == "nt": # Under windows offset is +1 because of additional newline char - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 9 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 9 else: - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 8 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 8 # Rotate files and remove old one - os.rename(testfile2, testfile3) - os.rename(testfile1, testfile2) + os.rename(testfile_path2, testfile_path3) + os.rename(testfile_path1, testfile_path2) - with open(testfile1, 'w') as f: - f.write("entry200\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("entry200\n") # Remove file afterwards to make sure not inode reuse happens - os.remove(testfile3) + os.remove(testfile_path3) # Now wait until rotation is detected self.wait_until( @@ -628,11 +628,11 @@ def test_state_after_rotation_ignore_older(self): # Check that offsets are correct if os.name == "nt": # Under windows offset is +1 because of additional newline char - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 10 - assert self.get_registry_entry_by_path(os.path.abspath(testfile2))["offset"] == 9 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 10 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 9 else: - assert self.get_registry_entry_by_path(os.path.abspath(testfile1))["offset"] == 9 - assert self.get_registry_entry_by_path(os.path.abspath(testfile2))["offset"] == 8 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 9 + assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 8 def test_clean_inactive(self): """ @@ -647,15 +647,15 @@ def test_clean_inactive(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/input1" - testfile2 = self.working_dir + "/log/input2" - testfile3 = self.working_dir + "/log/input3" + testfile_path1 = self.working_dir + "/log/input1" + testfile_path2 = self.working_dir + "/log/input2" + testfile_path3 = self.working_dir + "/log/input3" - with open(testfile1, 'w') as f: - f.write("first file\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("first file\n") - with open(testfile2, 'w') as f: - f.write("second file\n") + with open(testfile_path2, 'w') as testfile2: + testfile2.write("second file\n") filebeat = self.start_beat() @@ -681,8 +681,8 @@ def test_clean_inactive(self): "State removed for") == 2, max_timeout=15) - with open(testfile3, 'w') as f: - f.write("2\n") + with open(testfile_path3, 'w') as testfile3: + testfile3.write("2\n") # Write new file to make sure registrar is flushed again self.wait_until( @@ -719,14 +719,14 @@ def test_clean_removed(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/input1" - testfile2 = self.working_dir + "/log/input2" + testfile_path1 = self.working_dir + "/log/input1" + testfile_path2 = self.working_dir + "/log/input2" - with open(testfile1, 'w') as f: - f.write("file to be removed\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("file to be removed\n") - with open(testfile2, 'w') as f: - f.write("2\n") + with open(testfile_path2, 'w') as testfile2: + testfile2.write("2\n") filebeat = self.start_beat() @@ -746,7 +746,7 @@ def test_clean_removed(self): data = self.get_registry() assert len(data) == 2 - os.remove(testfile1) + os.remove(testfile_path1) # Wait until states are removed from prospectors self.wait_until( @@ -755,8 +755,8 @@ def test_clean_removed(self): max_timeout=15) # Add one more line to make sure registry is written - with open(testfile2, 'a') as f: - f.write("make sure registry is written\n") + with open(testfile_path2, 'a') as testfile2: + testfile2.write("make sure registry is written\n") self.wait_until( lambda: self.output_has(lines=3), @@ -774,7 +774,7 @@ def test_clean_removed(self): else: assert data[0]["offset"] == len("make sure registry is written\n" + "2\n") - def test_clean_removed_with_clean_inactive(self): + def test_clean_removed_with_clean_inactive(self): # pylint: disable=invalid-name """ Checks that files which were removed, the state is removed """ @@ -788,14 +788,14 @@ def test_clean_removed_with_clean_inactive(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/input1" - testfile2 = self.working_dir + "/log/input2" + testfile_path1 = self.working_dir + "/log/input1" + testfile_path2 = self.working_dir + "/log/input2" - with open(testfile1, 'w') as f: - f.write("file to be removed\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("file to be removed\n") - with open(testfile2, 'w') as f: - f.write("2\n") + with open(testfile_path2, 'w') as testfile2: + testfile2.write("2\n") filebeat = self.start_beat() @@ -811,7 +811,7 @@ def test_clean_removed_with_clean_inactive(self): data = self.get_registry() assert len(data) == 2 - os.remove(testfile1) + os.remove(testfile_path1) # Wait until states are removed from prospectors self.wait_until( @@ -820,8 +820,8 @@ def test_clean_removed_with_clean_inactive(self): max_timeout=15) # Add one more line to make sure registry is written - with open(testfile2, 'a') as f: - f.write("make sure registry is written\n") + with open(testfile_path2, 'a') as testfile2: + testfile2.write("make sure registry is written\n") self.wait_until( lambda: self.output_has(lines=3), @@ -853,9 +853,9 @@ def test_directory_failure(self): os.mkdir(self.working_dir + "/log/") os.mkdir(self.working_dir + "/registrar/") - testfile = self.working_dir + "/log/test.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + testfile_path = self.working_dir + "/log/test.log" + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") filebeat = self.start_beat() @@ -876,16 +876,16 @@ def test_symlink_failure(self): ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + testfile_path = self.working_dir + "/log/test.log" + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") registryfile = self.working_dir + "/registry" - with open(registryfile, 'w') as file: - file.write("[]") + with open(registryfile, 'w') as testfile: + testfile.write("[]") if os.name == "nt": - import win32file + import win32file # pylint: disable=import-error win32file.CreateSymbolicLink(self.working_dir + "/registry_symlink", registryfile, 0) else: os.symlink(registryfile, self.working_dir + "/registry_symlink") @@ -910,20 +910,21 @@ def test_invalid_state(self): os.mkdir(self.working_dir + "/log/") registry_file = self.working_dir + "/registry" - testfile = self.working_dir + "/log/test.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + testfile_path = self.working_dir + "/log/test.log" + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") - registry_file = self.working_dir + "/registry" - with open(registry_file, 'w') as file: + registry_file_path = self.working_dir + "/registry" + with open(registry_file_path, 'w') as registry_file: # Write invalid state - file.write("Hello World") + registry_file.write("Hello World") filebeat = self.start_beat() # Make sure states written appears one more time self.wait_until( - lambda: self.log_contains("CRIT Exiting: Could not start registrar: Error loading state"), + lambda: self.log_contains( + "CRIT Exiting: Could not start registrar: Error loading state"), max_timeout=10) filebeat.check_kill_and_wait(exit_code=1) @@ -940,17 +941,17 @@ def test_restart_state(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/test1.log" - testfile2 = self.working_dir + "/log/test2.log" - testfile3 = self.working_dir + "/log/test3.log" - testfile4 = self.working_dir + "/log/test4.log" + testfile_path1 = self.working_dir + "/log/test1.log" + testfile_path2 = self.working_dir + "/log/test2.log" + testfile_path3 = self.working_dir + "/log/test3.log" + testfile_path4 = self.working_dir + "/log/test4.log" - with open(testfile1, 'w') as file: - file.write("Hello World\n") - with open(testfile2, 'w') as file: - file.write("Hello World\n") - with open(testfile3, 'w') as file: - file.write("Hello World\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("Hello World\n") + with open(testfile_path2, 'w') as testfile2: + testfile2.write("Hello World\n") + with open(testfile_path3, 'w') as testfile3: + testfile3.write("Hello World\n") filebeat = self.start_beat() @@ -971,17 +972,19 @@ def test_restart_state(self): filebeat = self.start_beat(output="filebeat2.log") # Write additional file - with open(testfile4, 'w') as file: - file.write("Hello World\n") + with open(testfile_path4, 'w') as testfile4: + testfile4.write("Hello World\n") # Make sure all 4 states are persisted self.wait_until( - lambda: self.log_contains("Prospector states cleaned up. Before: 4, After: 4", logfile="filebeat2.log"), + lambda: self.log_contains( + "Prospector states cleaned up. Before: 4, After: 4", logfile="filebeat2.log"), max_timeout=10) # Wait until registry file is cleaned self.wait_until( - lambda: self.log_contains("Prospector states cleaned up. Before: 0, After: 0", logfile="filebeat2.log"), + lambda: self.log_contains( + "Prospector states cleaned up. Before: 0, After: 0", logfile="filebeat2.log"), max_timeout=10) filebeat.check_kill_and_wait() @@ -998,10 +1001,10 @@ def test_restart_state_reset(self): ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" + testfile_path = self.working_dir + "/log/test.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") filebeat = self.start_beat() @@ -1028,7 +1031,8 @@ def test_restart_state_reset(self): # Wait until prospectors are started self.wait_until( - lambda: self.log_contains_count("Starting prospector of type: log", logfile="filebeat2.log") >= 1, + lambda: self.log_contains_count( + "Starting prospector of type: log", logfile="filebeat2.log") >= 1, max_timeout=10) filebeat.check_kill_and_wait() @@ -1050,10 +1054,10 @@ def test_restart_state_reset_ttl(self): ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" + testfile_path = self.working_dir + "/log/test.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") filebeat = self.start_beat() @@ -1099,10 +1103,11 @@ def test_restart_state_reset_ttl(self): assert len(data) == 1 assert data[0]["ttl"] == 40 * 1000 * 1000 * 1000 - def test_restart_state_reset_ttl_with_space(self): + def test_restart_state_reset_ttl_with_space(self): # pylint: disable=invalid-name """ Test that ttl is reset after restart if clean_inactive changes - This time it is tested with a space in the filename to see if everything is loaded as expected + This time it is tested with a space in the filename to see if everything is loaded as + expected """ self.render_config_template( @@ -1112,10 +1117,10 @@ def test_restart_state_reset_ttl_with_space(self): ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test file.log" + testfile_path = self.working_dir + "/log/test file.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") filebeat = self.start_beat() @@ -1146,7 +1151,8 @@ def test_restart_state_reset_ttl_with_space(self): # Wait until new state is written self.wait_until( - lambda: self.log_contains("Flushing spooler because of timeout. Events flushed: ", logfile="filebeat2.log"), + lambda: self.log_contains( + "Flushing spooler because of timeout. Events flushed: ", logfile="filebeat2.log"), max_timeout=10) self.wait_until( @@ -1160,7 +1166,7 @@ def test_restart_state_reset_ttl_with_space(self): assert len(data) == 1 assert data[0]["ttl"] == 40 * 1000 * 1000 * 1000 - def test_restart_state_reset_ttl_no_clean_inactive(self): + def test_restart_state_reset_ttl_no_clean_inactive(self): # pylint: disable=invalid-name """ Test that ttl is reset after restart if clean_inactive is disabled """ @@ -1172,10 +1178,10 @@ def test_restart_state_reset_ttl_no_clean_inactive(self): ) os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" + testfile_path = self.working_dir + "/log/test.log" - with open(testfile, 'w') as file: - file.write("Hello World\n") + with open(testfile_path, 'w') as testfile: + testfile.write("Hello World\n") filebeat = self.start_beat() @@ -1200,7 +1206,8 @@ def test_restart_state_reset_ttl_no_clean_inactive(self): # Wait until prospectors are started self.wait_until( - lambda: self.log_contains("Flushing spooler because of timeout. Events flushed: ", logfile="filebeat2.log"), + lambda: self.log_contains( + "Flushing spooler because of timeout. Events flushed: ", logfile="filebeat2.log"), max_timeout=10) self.wait_until( @@ -1227,10 +1234,10 @@ def test_ignore_older_state(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/test.log" + testfile_path1 = self.working_dir + "/log/test.log" - with open(testfile1, 'w') as file: - file.write("Hello World\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("Hello World\n") time.sleep(1) @@ -1257,9 +1264,9 @@ def test_ignore_older_state(self): assert len(data) == 1 # Check that offset is set to the end of the file - assert data[0]["offset"] == os.path.getsize(testfile1) + assert data[0]["offset"] == os.path.getsize(testfile_path1) - def test_ignore_older_state_clean_inactive(self): + def test_ignore_older_state_clean_inactive(self): # pylint: disable=invalid-name """ Check that state for ignore_older is not persisted when falling under clean_inactive """ @@ -1272,10 +1279,10 @@ def test_ignore_older_state_clean_inactive(self): ) os.mkdir(self.working_dir + "/log/") - testfile1 = self.working_dir + "/log/test.log" + testfile_path1 = self.working_dir + "/log/test.log" - with open(testfile1, 'w') as file: - file.write("Hello World\n") + with open(testfile_path1, 'w') as testfile1: + testfile1.write("Hello World\n") time.sleep(2) @@ -1287,7 +1294,8 @@ def test_ignore_older_state_clean_inactive(self): max_timeout=10) self.wait_until( - lambda: self.log_contains("Do not write state for ignore_older because clean_inactive reached"), + lambda: self.log_contains( + "Do not write state for ignore_older because clean_inactive reached"), max_timeout=10) # Make sure state is loaded for file From 29a4de5a61f5e1d8671be3500b60a12727c2ff69 Mon Sep 17 00:00:00 2001 From: Giuseppe Valente Date: Tue, 21 Mar 2017 10:10:18 -0700 Subject: [PATCH 2/4] Add .pylintrc Disable all the warnings found globally, except for import-error which is just too broad. --- .pylintrc | 407 ++++++++++++++++++++++++ filebeat/tests/system/test_registrar.py | 16 +- 2 files changed, 415 insertions(+), 8 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 000000000000..e26e61647c5e --- /dev/null +++ b/.pylintrc @@ -0,0 +1,407 @@ +[MASTER] + +# Specify a configuration file. +#rcfile= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Use multiple processes to speed up Pylint. +jobs=1 + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Allow optimization of some AST trees. This will activate a peephole AST +# optimizer, which will apply various small optimizations. For instance, it can +# be used to obtain the result of joining multiple strings with the addition +# operator. Joining a lot of strings can lead to a maximum recursion error in +# Pylint and this flag can prevent that. It has one side effect, the resulting +# AST will be different than the one from reality. This option is deprecated +# and it will be removed in Pylint 2.0. +optimize-ast=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +disable=too-many-lines,too-many-public-methods,too-many-statements + + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html. You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". This option is deprecated +# and it will be removed in Pylint 2.0. +files-output=no + +# Tells whether to display a full report or only the messages +reports=yes + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + + +[BASIC] + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Regular expression matching correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for function names +function-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for variable names +variable-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Naming hint for constant names +const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression matching correct attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for attribute names +attr-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for argument names +argument-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming hint for class attribute names +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming hint for inline iteration names +inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ + +# Regular expression matching correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Naming hint for class names +class-name-hint=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Naming hint for module names +module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression matching correct method names +method-rgx=[a-z_][a-z0-9_]{2,50}$ + +# Naming hint for method names +method-name-hint=[a-z_][a-z0-9_]{2,50}$ + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + + +[ELIF] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=100 + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma,dict-separator + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[TYPECHECK] + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=(_+[a-zA-Z0-9]*?$)|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,future.builtins + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + + +[IMPORTS] + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/filebeat/tests/system/test_registrar.py b/filebeat/tests/system/test_registrar.py index 3ed745662740..e1b1e809407f 100644 --- a/filebeat/tests/system/test_registrar.py +++ b/filebeat/tests/system/test_registrar.py @@ -1,4 +1,4 @@ -"""Test the registrar""" # pylint: disable=too-many-lines +"""Test the registrar""" import os import platform @@ -14,7 +14,7 @@ # * Check what happens when registrar file is deleted -class Test(BaseTest): # pylint: disable=too-many-public-methods +class Test(BaseTest): """Test class""" def test_registrar_file_content(self): @@ -131,7 +131,7 @@ def test_registrar_files(self): # Check that 2 files are port of the registrar file assert len(data) == 2 - def test_custom_registry_file_location(self): # pylint: disable=invalid-name + def test_custom_registry_file_location(self): """ Check that when a custom registry file is used, the path is created automatically. @@ -557,7 +557,7 @@ def test_state_after_rotation(self): assert self.get_registry_entry_by_path(os.path.abspath(testfile_path1))["offset"] == 9 assert self.get_registry_entry_by_path(os.path.abspath(testfile_path2))["offset"] == 8 - def test_state_after_rotation_ignore_older(self): # pylint: disable=invalid-name + def test_state_after_rotation_ignore_older(self): """ Checks that the state is written correctly after rotation and ignore older """ @@ -774,7 +774,7 @@ def test_clean_removed(self): else: assert data[0]["offset"] == len("make sure registry is written\n" + "2\n") - def test_clean_removed_with_clean_inactive(self): # pylint: disable=invalid-name + def test_clean_removed_with_clean_inactive(self): """ Checks that files which were removed, the state is removed """ @@ -1103,7 +1103,7 @@ def test_restart_state_reset_ttl(self): assert len(data) == 1 assert data[0]["ttl"] == 40 * 1000 * 1000 * 1000 - def test_restart_state_reset_ttl_with_space(self): # pylint: disable=invalid-name + def test_restart_state_reset_ttl_with_space(self): """ Test that ttl is reset after restart if clean_inactive changes This time it is tested with a space in the filename to see if everything is loaded as @@ -1166,7 +1166,7 @@ def test_restart_state_reset_ttl_with_space(self): # pylint: disable=invalid-na assert len(data) == 1 assert data[0]["ttl"] == 40 * 1000 * 1000 * 1000 - def test_restart_state_reset_ttl_no_clean_inactive(self): # pylint: disable=invalid-name + def test_restart_state_reset_ttl_no_clean_inactive(self): """ Test that ttl is reset after restart if clean_inactive is disabled """ @@ -1266,7 +1266,7 @@ def test_ignore_older_state(self): # Check that offset is set to the end of the file assert data[0]["offset"] == os.path.getsize(testfile_path1) - def test_ignore_older_state_clean_inactive(self): # pylint: disable=invalid-name + def test_ignore_older_state_clean_inactive(self): """ Check that state for ignore_older is not persisted when falling under clean_inactive """ From 342aa5feb5cca5b8baa1d4333afb461fa70b6dfa Mon Sep 17 00:00:00 2001 From: Giuseppe Valente Date: Wed, 22 Mar 2017 10:36:33 -0700 Subject: [PATCH 3/4] pylintrc: remove unmodified options --- .pylintrc | 399 ------------------------------------------------------ 1 file changed, 399 deletions(-) diff --git a/.pylintrc b/.pylintrc index e26e61647c5e..dc93d6f9d6ee 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,407 +1,8 @@ -[MASTER] - -# Specify a configuration file. -#rcfile= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Add files or directories to the blacklist. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the blacklist. The -# regex matches against base names, not paths. -ignore-patterns= - -# Pickle collected data for later comparisons. -persistent=yes - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Allow optimization of some AST trees. This will activate a peephole AST -# optimizer, which will apply various small optimizations. For instance, it can -# be used to obtain the result of joining multiple strings with the addition -# operator. Joining a lot of strings can lead to a maximum recursion error in -# Pylint and this flag can prevent that. It has one side effect, the resulting -# AST will be different than the one from reality. This option is deprecated -# and it will be removed in Pylint 2.0. -optimize-ast=no - - [MESSAGES CONTROL] -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -#enable= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" disable=too-many-lines,too-many-public-methods,too-many-statements -[REPORTS] - -# Set the output format. Available formats are text, parseable, colorized, msvs -# (visual studio) and html. You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Put messages in a separate file for each module / package specified on the -# command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". This option is deprecated -# and it will be removed in Pylint 2.0. -files-output=no - -# Tells whether to display a full report or only the messages -reports=yes - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - - [BASIC] -# Good variable names which should always be accepted, separated by a comma -good-names=i,j,k,ex,Run,_ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct function names -function-rgx=[a-z_][a-z0-9_]{2,30}$ - -# Naming hint for function names -function-name-hint=[a-z_][a-z0-9_]{2,30}$ - -# Regular expression matching correct variable names -variable-rgx=[a-z_][a-z0-9_]{2,30}$ - -# Naming hint for variable names -variable-name-hint=[a-z_][a-z0-9_]{2,30}$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Regular expression matching correct attribute names -attr-rgx=[a-z_][a-z0-9_]{2,30}$ - -# Naming hint for attribute names -attr-name-hint=[a-z_][a-z0-9_]{2,30}$ - -# Regular expression matching correct argument names -argument-rgx=[a-z_][a-z0-9_]{2,30}$ - -# Naming hint for argument names -argument-name-hint=[a-z_][a-z0-9_]{2,30}$ - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct class names -class-rgx=[A-Z_][a-zA-Z0-9]+$ - -# Naming hint for class names -class-name-hint=[A-Z_][a-zA-Z0-9]+$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Regular expression matching correct method names method-rgx=[a-z_][a-z0-9_]{2,50}$ - -# Naming hint for method names -method-name-hint=[a-z_][a-z0-9_]{2,50}$ - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - - -[ELIF] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[FORMAT] - -# Maximum number of characters on a single line. -max-line-length=100 - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - -# Maximum number of lines in a module -max-module-lines=1000 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO - - -[SIMILARITIES] - -# Minimum lines number of a similarity. -min-similarity-lines=4 - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=no - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[TYPECHECK] - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules= - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - - -[VARIABLES] - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=(_+[a-zA-Z0-9]*?$)|dummy - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.* - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of statements in function / method body -max-statements=50 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of attributes for a class (see R0902). -max-attributes=7 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=2 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - - -[IMPORTS] - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=regsub,TERMIOS,Bastion,rexec - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=Exception From d0a27d822b095f00002c9ae48bb8477d9f039321 Mon Sep 17 00:00:00 2001 From: Giuseppe Valente Date: Wed, 22 Mar 2017 10:41:21 -0700 Subject: [PATCH 4/4] pylintrc: adjust max line length to autopep8 settings --- .pylintrc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pylintrc b/.pylintrc index dc93d6f9d6ee..dc2109150520 100644 --- a/.pylintrc +++ b/.pylintrc @@ -6,3 +6,8 @@ disable=too-many-lines,too-many-public-methods,too-many-statements [BASIC] method-rgx=[a-z_][a-z0-9_]{2,50}$ + + +[FORMAT] + +max-line-length=120