<commit_before>#!/usr/bin/env python

import pytest
if pytest.PLATFORM == "win32":
    pytest.skip("Unsupported Platform")

from io import BytesIO
from circuits import Component
from circuits.io import File, Write, Close


class FileApp(Component):

    def init(self, *args, **kwargs):
        self.file = File(*args, **kwargs).register(self)

        self.eof = False
        self.buffer = BytesIO()

    def read(self, data):
        self.buffer.write(data)

    def eof(self):
        self.eof = True


def test_read_write(manager, watcher, tmpdir):
    filename = str(tmpdir.ensure("helloworld.txt"))

    app = FileApp(filename, "w").register(manager)<commit_msg>Added unit test testing opening file objects<commit_after>#!/usr/bin/env python

import pytest
if pytest.PLATFORM == "win32":
    pytest.skip("Unsupported Platform")

from io import BytesIO
from circuits import Component
from circuits.io import File, Write, Close


class FileApp(Component):

    def init(self, *args, **kwargs):
        self.file = File(*args, **kwargs).register(self)

        self.eof = False
        self.buffer = BytesIO()

    def read(self, data):
        self.buffer.write(data)

    def eof(self):
        self.eof = True


def test_open_fileobj(manager, watcher, tmpdir):
    filename = str(tmpdir.ensure("helloworld.txt"))
    with open(filename, "w") as f:
        f.write("Hello World!")

    fileobj = open(filename, "r")
    print(type(fileobj))

    app = FileApp(fileobj).register(manager)
    assert watcher.wait("opened", app.file.channel)

    assert watcher.wait("eof", app.file.channel)

    app.fire(Close(), app.file.channel)
    assert watcher.wait("closed", app.file.channel)

    app.unregister()
    assert watcher.wait("unregistered")

    s = app.buffer.getvalue()
    assert s == b"Hello World!"


def test_read_write(manager, watcher, tmpdir):
    filename = str(tmpdir.ensure("helloworld.txt"))

    app = FileApp(filename, "w").register(manager)
{'fraction_non_alphanumeric': 0.13435114503816795, 'fraction_numerical': 0.002035623409669211, 'mean_word_length': 3.478359908883827, 'pattern_counts': {'":': 2, '<': 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': '3476067', 'n_tokens_mistral': 651, 'n_tokens_neox': 628, 'n_words': 150}