<commit_before>from ben10.filesystem import OpenReadOnlyFile
import os
import pytest
import sys



pytest_plugins = ["ben10.fixtures"]



@pytest.fixture
def test_filename(embed_data):
    filename = embed_data.GetDataFilename('test_fileutils.tst')
    file(filename, 'w').write('empty')
    return filename



#=======================================================================================================================
# Test
#=======================================================================================================================
class Test:

    def testOpenReadOnlyFile__serial(self, test_filename, monkeypatch):
        if sys.platform == 'win32':

            def ResetFlags():
                self.binary_flag = None
                self.sequential_flag = None

            self.original_open = os.open
            def MockOpen(filename, flags):
                '''
                '''
                self.binary_flag = flags & os.O_BINARY
                self.sequential_flag = flags & os.O_SEQUENTIAL
                return self.original_open(filename, flags)


            self.open_file = None
            monkeypatch.setattr(os, 'open', MockOpen)

            try:
                # Check text, random
                ResetFlags()
                self.open_file = OpenReadOnlyFile(test_filename)
                assert self.open_file.mode == 'r'
                assert self.binary_flag is None
                assert self.sequential_flag is None
                self.open_file.close()

                # Check binary, random
                ResetFlags()
                self.open_file = OpenReadOnlyFile(test_filename, binary=True)
                assert self.open_file.mode == 'rb'
                assert self.binary_flag is None
                assert self.sequential_flag is None
                self.open_file.close()

                # Check binary, sequential
                ResetFlags()
                self.open_file = OpenReadOnlyFile(test_filename, binary=True, sequential=True)
                assert self.open_file.mode == 'rb'
                assert self.binary_flag is not None
                assert self.sequential_flag is not None
                self.open_file.close()

            finally:
                if self.open_file:
                    self.open_file.close()<commit_msg>Removed dependency from coilib50.<commit_after>from ben10.filesystem import OpenReadOnlyFile
import os
import pytest
import sys



pytest_plugins = ["ben10.fixtures"]



@pytest.fixture
def test_filename(embed_data):
    filename = embed_data.GetDataFilename('test_fileutils.tst')
    file(filename, 'w').write('empty')
    return filename



#=======================================================================================================================
# Test
#=======================================================================================================================
class Test:

    def testOpenReadOnlyFile__serial(self, monkeypatch, test_filename):
        if sys.platform == 'win32':

            def ResetFlags():
                self.binary_flag = None
                self.sequential_flag = None

            self.original_open = os.open
            def MockOpen(filename, flags):
                '''
                '''
                self.binary_flag = flags & os.O_BINARY
                self.sequential_flag = flags & os.O_SEQUENTIAL
                return self.original_open(filename, flags)


            monkeypatch.setattr(os, 'open', MockOpen)

            self.open_file = None
            try:
                # Check text, random
                ResetFlags()
                self.open_file = OpenReadOnlyFile(test_filename)
                assert self.open_file.mode == 'r'
                assert self.binary_flag is None
                assert self.sequential_flag is None
                self.open_file.close()

                # Check binary, random
                ResetFlags()
                self.open_file = OpenReadOnlyFile(test_filename, binary=True)
                assert self.open_file.mode == 'rb'
                assert self.binary_flag is None
                assert self.sequential_flag is None
                self.open_file.close()

                # Check binary, sequential
                ResetFlags()
                self.open_file = OpenReadOnlyFile(test_filename, binary=True, sequential=True)
                assert self.open_file.mode == 'rb'
                assert self.binary_flag is not None
                assert self.sequential_flag is not None
                self.open_file.close()
            finally:
                if self.open_file:
                    self.open_file.close()
{'fraction_non_alphanumeric': 0.17046180038306022, 'fraction_numerical': 0.0029793573100659713, 'mean_word_length': 1.944862155388471, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7246838', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1080, 'n_words': 242}