<commit_before>'use strict';

const assert = require('assert');
const mockRequire = require('mock-require');
const MockLinux = require('./mocks/linux');
const MockEpoll = require('./mocks/epoll');

mockRequire('epoll', MockEpoll);
const Gpio = require('../onoff').Gpio;


describe('read', () => {
  let gpio;
  let pin;

  beforeEach(() => {
    pin = 4;
    MockLinux.gpio(pin);
    gpio = new Gpio(pin, 'out');
  });


  it('reads high', (done) => {
    const expected = 1;
    MockLinux.write(pin, expected);
    gpio.read((err, actual) => {
      assert.deepEqual(actual, expected);
      done();
    });
  });

  it('reads low', (done) => {
    const expected = 0;
    MockLinux.write(pin, expected);
    gpio.read((err, actual) => {
      assert.deepEqual(actual, expected);
      done();
    });
  });

  it('fails', (done) => {
    const expected = 'EBADF';
    const valueFd = gpio._valueFd;
    gpio._valueFd = -1;
    gpio.read((err, value) => {
      gpio._valueFd = valueFd;
      const actual = err.code;
      assert.deepEqual(actual, expected);
      done();
    });
  });


  afterEach(() => {
    gpio.unexport();
    MockLinux.restore();
  });
});
<commit_msg>use a valid file descriptor number in read fails test<commit_after>'use strict';

const assert = require('assert');
const mockRequire = require('mock-require');
const MockLinux = require('./mocks/linux');
const MockEpoll = require('./mocks/epoll');

mockRequire('epoll', MockEpoll);
const Gpio = require('../onoff').Gpio;


describe('read', () => {
  let gpio;
  let pin;

  beforeEach(() => {
    pin = 4;
    MockLinux.gpio(pin);
    gpio = new Gpio(pin, 'out');
  });


  it('reads high', (done) => {
    const expected = 1;
    MockLinux.write(pin, expected);
    gpio.read((err, actual) => {
      assert.deepEqual(actual, expected);
      done();
    });
  });

  it('reads low', (done) => {
    const expected = 0;
    MockLinux.write(pin, expected);
    gpio.read((err, actual) => {
      assert.deepEqual(actual, expected);
      done();
    });
  });

  it('fails', (done) => {
    const expected = 'EBADF';
    const valueFd = gpio._valueFd;
    gpio._valueFd = 1e6;
    gpio.read((err, value) => {
      gpio._valueFd = valueFd;
      const actual = err.code;
      assert.deepEqual(actual, expected);
      done();
    });
  });


  afterEach(() => {
    gpio.unexport();
    MockLinux.restore();
  });
});

{'fraction_non_alphanumeric': 0.1913297207169654, 'fraction_numerical': 0.003751563151313047, 'mean_word_length': 2.877221324717286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '563565', 'n_tokens_mistral': 854, 'n_tokens_neox': 806, 'n_words': 171}