Ejemplo n.º 1
0
    def setUp(self):
        """Setup directory for test."""
        self.test_dir = tempfile.mkdtemp()
        self.files_not_zip = []
        self.files_to_zip = []

        build_info = os.path.join(self.test_dir, 'BUILD_INFO-x')
        unittest_lib.create_file(build_info, ORIGINAL_SIZE_BYTE)
        self.files_not_zip.append(build_info)

        file1 = os.path.join(self.test_dir, 'file1.xml')
        unittest_lib.create_file(file1, ORIGINAL_SIZE_BYTE)
        self.files_to_zip.append(file1)

        file2 = os.path.join(self.test_dir, 'file2.jpg')
        unittest_lib.create_file(file2, ORIGINAL_SIZE_BYTE)
        self.files_not_zip.append(file2)

        file3 = os.path.join(self.test_dir, 'file3.log')
        unittest_lib.create_file(file3, ORIGINAL_SIZE_BYTE)
        self.files_to_zip.append(file3)

        folder1 = os.path.join(self.test_dir, 'folder1')
        os.mkdir(folder1)
        file4 = os.path.join(folder1, 'file4')
        unittest_lib.create_file(file4, ORIGINAL_SIZE_BYTE)
        self.files_to_zip.append(file4)
Ejemplo n.º 2
0
    def setUp(self):
        """Setup directory to match the file structure in MERGED_SUMMARY."""
        self.test_dir = tempfile.mkdtemp()

        folder = os.path.join(self.test_dir, 'files_to_shink')
        os.mkdir(folder)
        file1 = os.path.join(folder, 'file.txt')
        unittest_lib.create_file(file1, LARGE_SIZE)

        folder = os.path.join(self.test_dir, 'files_to_zip')
        os.mkdir(folder)
        file1 = os.path.join(folder, 'file.xml')
        unittest_lib.create_file(file1, LARGE_SIZE)

        folder = os.path.join(self.test_dir, 'files_to_delete')
        os.mkdir(folder)
        file1 = os.path.join(folder, 'file.png')
        unittest_lib.create_file(file1, LARGE_SIZE)

        folder = os.path.join(self.test_dir, 'files_to_dedupe')
        os.mkdir(folder)
        for i in range(5):
            time.sleep(0.01)
            file1 = os.path.join(folder, 'file_%d.dmp' % i)
            unittest_lib.create_file(file1, SMALL_SIZE)
Ejemplo n.º 3
0
    def setUp(self):
        """Setup directory for test."""
        self.test_dir = tempfile.mkdtemp()
        file1 = os.path.join(self.test_dir, 'file1')
        unittest_lib.create_file(file1)
        folder1 = os.path.join(self.test_dir, 'folder1')
        os.mkdir(folder1)
        file2 = os.path.join(folder1, 'file2')
        unittest_lib.create_file(file2)
        file3 = os.path.join(folder1, 'file3')
        unittest_lib.create_file(file3)

        folder2 = os.path.join(self.test_dir, 'folder2')
        os.mkdir(folder2)
        file4 = os.path.join(folder2, 'file2')
        unittest_lib.create_file(file4)

        symlink = os.path.join(folder1, 'symlink')
        os.symlink(folder2, symlink)
Ejemplo n.º 4
0
    def setUp(self):
        """Setup directory for test."""
        self.test_dir = tempfile.mkdtemp()
        self.files_to_keep = []
        self.files_to_delete = []
        modification_time = int(time.time()) - 1000

        # Files to be deduped in the root directory of result dir.
        for i in range(6):
            file_name = 'file_%d' % i
            f = os.path.join(self.test_dir, file_name)
            unittest_lib.create_file(f, unittest_lib.SIZE)
            os.utime(f, (modification_time, modification_time))
            modification_time += 1
            if (i < dedupe_file_throttler.OLDEST_FILES_TO_KEEP_COUNT or
                    i >= 6 - dedupe_file_throttler.NEWEST_FILES_TO_KEEP_COUNT):
                self.files_to_keep.append(f)
            else:
                self.files_to_delete.append(f)

        folder1 = os.path.join(self.test_dir, 'folder1')
        os.mkdir(folder1)

        # Files should not be deduped.
        for i in range(3):
            file_name = 'file_not_dedupe_%d' % i
            f = os.path.join(folder1, file_name)
            unittest_lib.create_file(f, unittest_lib.SIZE)
            self.files_to_keep.append(f)

        # Files to be deduped in the sub directory of result dir.
        for i in range(10):
            file_name = 'file_in_sub_dir%d' % i
            f = os.path.join(folder1, file_name)
            unittest_lib.create_file(f, unittest_lib.SIZE)
            os.utime(f, (modification_time, modification_time))
            modification_time += 1
            if (i < dedupe_file_throttler.OLDEST_FILES_TO_KEEP_COUNT or i >=
                    10 - dedupe_file_throttler.NEWEST_FILES_TO_KEEP_COUNT):
                self.files_to_keep.append(f)
            else:
                self.files_to_delete.append(f)
    def setUp(self):
        """Setup directory for test."""
        self.test_dir = tempfile.mkdtemp()
        self.files_not_deleted = []
        self.files_to_delete = []

        file1 = os.path.join(self.test_dir, 'file1.xml')
        unittest_lib.create_file(file1, LARGE_SIZE_BYTE)
        self.files_to_delete.append(file1)

        file2 = os.path.join(self.test_dir, 'file2.jpg')
        unittest_lib.create_file(file2, LARGE_SIZE_BYTE)
        self.files_to_delete.append(file2)

        file_to_keep = os.path.join(self.test_dir, 'file_to_keep')
        unittest_lib.create_file(file_to_keep, MEDIUM_SIZE_BYTE)
        self.files_not_deleted.append(file_to_keep)

        file3 = os.path.join(self.test_dir, 'file3.log')
        unittest_lib.create_file(file3, SMALL_SIZE_BYTE)
        self.files_not_deleted.append(file3)

        folder1 = os.path.join(self.test_dir, 'folder1')
        os.mkdir(folder1)
        file4 = os.path.join(folder1, 'file4')
        unittest_lib.create_file(file4, LARGE_SIZE_BYTE)
        self.files_to_delete.append(file4)

        protected_file = os.path.join(folder1, 'keyval')
        unittest_lib.create_file(protected_file, LARGE_SIZE_BYTE)
        self.files_not_deleted.append(protected_file)

        folder2 = os.path.join(self.test_dir, 'AndroidDeviceXXX')
        os.mkdir(folder2)
        file5 = os.path.join(folder2, 'file5')
        unittest_lib.create_file(file5, LARGE_SIZE_BYTE)
        self.files_not_deleted.append(file5)

        test_run = os.path.join(self.test_dir, 'test_run_details.txt')
        unittest_lib.create_file(test_run, LARGE_SIZE_BYTE)
        self.files_not_deleted.append(test_run)

        perf_data = os.path.join(self.test_dir, 'chrome.123.perf.data')
        unittest_lib.create_file(perf_data, LARGE_SIZE_BYTE)
        self.files_not_deleted.append(perf_data)
Ejemplo n.º 6
0
 def TestBuildFromPath_SingleFile(self):
     """Test method build_from_path for a single file."""
     file1 = os.path.join(self.test_dir, 'file1')
     unittest_lib.create_file(file1)
     summary = result_info.ResultInfo.build_from_path(file1)
     self.assertEqual(_EXPECTED_SINGLE_FILE_SUMMARY, summary)
Ejemplo n.º 7
0
    def setUp(self):
        """Setup directory to match the file structure in MERGED_SUMMARY."""
        self.test_dir = tempfile.mkdtemp() + '/'
        file1 = os.path.join(self.test_dir, 'file1')
        unittest_lib.create_file(file1)
        file2 = os.path.join(self.test_dir, 'file2')
        unittest_lib.create_file(file2, 2*SIZE)
        file3 = os.path.join(self.test_dir, 'file3')
        unittest_lib.create_file(file3, SIZE)
        file4 = os.path.join(self.test_dir, 'file4')
        unittest_lib.create_file(file4, SIZE)
        folder1 = os.path.join(self.test_dir, 'folder1')
        os.mkdir(folder1)
        file4 = os.path.join(folder1, 'file4')
        unittest_lib.create_file(file4, SIZE)

        # Used to test summary in subdirectory.
        folder3 = os.path.join(self.test_dir, 'folder3')
        os.mkdir(folder3)
        folder31 = os.path.join(folder3, 'folder31')
        os.mkdir(folder31)
        file10 = os.path.join(folder31, 'file10')
        unittest_lib.create_file(file10, SIZE)

        folder2 = os.path.join(self.test_dir, 'folder2')
        os.mkdir(folder2)
        server_file = os.path.join(folder2, 'server_file')
        unittest_lib.create_file(server_file, 10*SIZE)
        folder_not_overwritten = os.path.join(
                self.test_dir, 'folder_not_overwritten')
        os.mkdir(folder_not_overwritten)
        file1 = os.path.join(folder_not_overwritten, 'file1')
        unittest_lib.create_file(file1)
        file_to_be_overwritten = os.path.join(
                self.test_dir, 'file_to_be_overwritten')
        os.mkdir(file_to_be_overwritten)
        file1 = os.path.join(file_to_be_overwritten, 'file1')
        unittest_lib.create_file(file1)

        # Save summary file to test_dir
        self.summary_1 = os.path.join(self.test_dir, 'dir_summary_1.json')
        with open(self.summary_1, 'w') as f:
            json.dump(SUMMARY_1, f)
        # Wait for 10ms, to make sure summary_2 has a later time stamp.
        time.sleep(0.01)
        self.summary_2 = os.path.join(self.test_dir, 'dir_summary_2.json')
        with open(self.summary_2, 'w') as f:
            json.dump(SUMMARY_2, f)
        time.sleep(0.01)
        self.summary_3 = os.path.join(self.test_dir, 'folder3', 'folder31',
                                      'dir_summary_3.json')
        with open(self.summary_3, 'w') as f:
            json.dump(SUMMARY_3, f)
Ejemplo n.º 8
0
    def setUp(self):
        """Setup directory for test."""
        self.test_dir = tempfile.mkdtemp()
        self.files_not_shrink = []
        self.files_to_shrink = []

        build_info = os.path.join(self.test_dir, 'BUILD_INFO-HT7591A00171')
        unittest_lib.create_file(build_info, ORIGINAL_SIZE_BYTE)
        self.files_not_shrink.append(build_info)

        file1 = os.path.join(self.test_dir, 'file1.xml')
        unittest_lib.create_file(file1, ORIGINAL_SIZE_BYTE)
        self.files_not_shrink.append(file1)

        file2 = os.path.join(self.test_dir, 'file2.jpg')
        unittest_lib.create_file(file2, ORIGINAL_SIZE_BYTE)
        self.files_not_shrink.append(file2)

        file3 = os.path.join(self.test_dir, 'file3.log')
        unittest_lib.create_file(file3, ORIGINAL_SIZE_BYTE)
        self.files_to_shrink.append(file3)
        os.utime(file3, (OLD_TIME, OLD_TIME))

        file4 = os.path.join(self.test_dir, 'test_run_details.txt')
        unittest_lib.create_file(file4, ORIGINAL_SIZE_BYTE)
        self.files_not_shrink.append(file4)

        folder1 = os.path.join(self.test_dir, 'folder1')
        os.mkdir(folder1)
        file4 = os.path.join(folder1, 'file4')
        unittest_lib.create_file(file4, ORIGINAL_SIZE_BYTE)
        self.files_to_shrink.append(file4)
        os.utime(file4, (OLD_TIME, OLD_TIME))
Ejemplo n.º 9
0
    def setUp(self):
        """Setup directory for test."""
        self.test_dir = tempfile.mkdtemp()

        self.file_to_shrink = os.path.join(self.test_dir, 'file1.txt')
        unittest_lib.create_file(self.file_to_shrink, LARGE_SIZE_BYTE)