def test_evaluate_negative_specs(self): self.runner([':-60'], item_count=80) self.sp = mod.SpecProcessor(self.specs) assert self.sp.specs_evaluator(7) is True assert self.sp.specs_evaluator(33) is False self.runner(['-60:-40'], item_count=80) self.sp = mod.SpecProcessor(self.specs) assert self.sp.specs_evaluator(7) is False assert self.sp.specs_evaluator(25) is True assert self.sp.specs_evaluator(78) is False self.runner(['10', '50:-10'], item_count=80) self.sp = mod.SpecProcessor(self.specs) assert self.sp.specs_evaluator(10) assert self.sp.specs_evaluator(5) is False assert self.sp.specs_evaluator(50) assert self.sp.specs_evaluator(69) assert self.sp.specs_evaluator(79) is False self.runner(['10:-1'], item_count=80) self.sp = mod.SpecProcessor(self.specs) assert self.sp.specs_evaluator(5) is False assert self.sp.specs_evaluator(10) assert self.sp.specs_evaluator(78) assert self.sp.specs_evaluator(79) is False assert self.sp.specs_evaluator(80) is False
def test_evaluate_all(self): self.runner([':'], item_count=80) self.sp = mod.SpecProcessor(self.specs) assert self.sp.specs_evaluator(5) is True assert self.sp.specs_evaluator(7) is True
def test_header_with_nonmatching_name(self): with pytest.raises(SystemExit): self.runner(['gorilla'], loc=0, item_count=80, header=['account_id', 'cust_id', 'zip']) self.sp = mod.SpecProcessor(self.specs)
def test_header_with_name_range_and_spaces(self): self.runner(['account_id : zip'], loc=0, item_count=80, header=['account_id', 'cust_id', 'zip']) self.sp = mod.SpecProcessor(self.specs) assert self.sp.index == [0, 1]
def test_evaluate_positive_specs(self): self.runner(['5', '7', '10:16'], item_count=80) self.sp = mod.SpecProcessor(self.specs) assert self.sp.index == [5, 7, 10, 11, 12, 13, 14, 15] assert self.sp.specs_evaluator(5) is True assert self.sp.specs_evaluator(50) is False assert self.sp.specs_evaluator(13) is True
def simple_runner(self, spec_strings, loc, spec_type='incl_rec', item_count=4, header=None): """ Creates the Spec Processor object with default settings for the specification and record length. """ specifications = mod.Specifications(spec_type, specs_strings=spec_strings, header=header, infile_item_count=item_count) self.sp = mod.SpecProcessor(specifications) return self.sp.specs_evaluator(loc)
def test_invalid_data_without_header(self): # missing colon: with pytest.raises(mod.UnidentifiableNonNumericSpec): self.runner(['2 5'], loc=0, item_count=80) # extra colon: with pytest.raises(SystemExit): self.runner(['2:5:1:6'], loc=0, item_count=80) # test a starting number larger than ending: with pytest.raises(SystemExit): self.runner(['5:2'], loc=0, item_count=80) self.sp = mod.SpecProcessor(self.specs) # column names, but no header: with pytest.raises(mod.UnidentifiableNonNumericSpec): self.runner(['account_id'], loc=0, item_count=80)
def test_all_conditions(self): self.runner(['account_id'], loc=0, item_count=80, header=['account_id', 'cust_id', 'zip']) self.sp = mod.SpecProcessor(self.specs) assert self.sp.index == [0] # Single Cols specs = mod.Specifications(spec_type='incl_rec', specs_strings=['5'], infile_item_count=80) assert self.sp._spec_item_check(specs.specs_final[0], 5) # Ranges: specs = mod.Specifications(spec_type='incl_rec', specs_strings=['5:10:1']) assert self.sp._spec_item_check(specs.specs_final[0], 5) assert self.sp._spec_item_check(specs.specs_final[0], 9) assert self.sp._spec_item_check(specs.specs_final[0], 10) is False
def _setup_slicers(self) -> None: self.incl_rec_slicer = slicer.SpecProcessor(self.rec_specs) self.excl_rec_slicer = slicer.SpecProcessor(self.exrec_specs) self.incl_col_slicer = slicer.SpecProcessor(self.col_specs) self.excl_col_slicer = slicer.SpecProcessor(self.excol_specs)