def test_match_path(self): f = sample_data.file() assert self.utils._match_file(f, FilterAttribute.PATH, "bonkey.txt", FilterAction.INCLUDE, FilterModifier.ANY) assert not self.utils._match_file(f, FilterAttribute.PATH, "plonkey.txt", FilterAction.INCLUDE, FilterModifier.ANY)
def test_keep_file(self): f = sample_data.file() self.assertTrue(self.utils._keep_file(True, FilterAction.INCLUDE)) self.assertFalse(self.utils._keep_file(True, FilterAction.EXCLUDE)) self.assertFalse(self.utils._keep_file(False, FilterAction.INCLUDE)) self.assertTrue(self.utils._keep_file(False, FilterAction.EXCLUDE))
def test_match_license(self): f = sample_data.file() assert self.utils._match_file(f, FilterAttribute.LICENSE, "gpl-2.0-or-later", FilterAction.INCLUDE, FilterModifier.ANY) # file has both gpl3 and gpl2, thus false assert not self.utils._match_file( f, FilterAttribute.LICENSE, "gpl-2.0-or-later", FilterAction.INCLUDE, FilterModifier.ONLY) assert not self.utils._match_file(f, FilterAttribute.LICENSE, "bsd-4-Clause", FilterAction.INCLUDE, FilterModifier.ANY)
def test_match_path_bad_indata(self): f = sample_data.file() self.assertRaises( Exception, lambda: self.utils. _match_file(None, FilterAttribute.PATH, "bonkey.txt", FilterAction. INCLUDE, FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils._match_file(f, None, "bonkey.txt", FilterAction. INCLUDE, FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils. _match_file(f, "incorrect", "bonkey.txt", FilterAction.INCLUDE, FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils. _match_file(f, FilterAttribute.PATH, None, FilterAction.INCLUDE, FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils._match_file(f, FilterAttribute.PATH, set( ), FilterAction.INCLUDE, FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils. _match_file(f, FilterAttribute.PATH, "bonkey.txt", None, FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils. _match_file(f, FilterAttribute.PATH, "bonkey.txt", "incorrect", FilterModifier.ANY)) self.assertRaises( Exception, lambda: self.utils. _match_file(f, FilterAttribute.PATH, "bonkey.txt", FilterAction. INCLUDE, None)) self.assertRaises( Exception, lambda: self.utils. _match_file(f, FilterAttribute.PATH, "bonkey.txt", FilterAction. INCLUDE, "incorrect"))
def test_extract_license(self): f = sample_data.file() fl = self.utils._extract_license(f) expected_l = {'gpl-3.0-or-later', 'gpl-2.0-or-later'} self.assertTrue(expected_l == fl)
def test_extract_license(self): lic = self.utils._extract_license(sample_data.file()) self.assertTrue( lic == \ {"gpl-2.0-or-later", "gpl-3.0-or-later"} or \ {"gpl-3.0-or-later", "gpl-2.0-or-later"})
def test_isdir(self): self.assertFalse(self.utils._isdir(sample_data.file())) self.assertTrue(self.utils._isdir(sample_data.dir()))