Skip to content

Commit

Permalink
Merge pull request #13 from fossology/feat/ci/test
Browse files Browse the repository at this point in the history
feat(ci): Use Github actions to run unittest
  • Loading branch information
Kaushl2208 authored Jul 29, 2020
2 parents c6a1a99 + e3ea644 commit 8709011
Show file tree
Hide file tree
Showing 23 changed files with 313 additions and 306 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Unit Tests

on:
push:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.5', '3.6', '3.7', '3.8']

name: Unit Tests on ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Run tests
run: python testScript.py

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<p align="center">

![python version](https://img.shields.io/badge/Python-v3%2B-blue)
![Unit Tests](https://github.com/fossology/Nirjas/workflows/Unit%20Tests/badge.svg)
![status](https://img.shields.io/pypi/status/Nirjas)
[![HitCount](http://hits.dwyl.com/fossology/Nirjas.svg)](http://hits.dwyl.com/fossology/Nirjas)
![License LGPL-2.1](https://img.shields.io/github/license/fossology/nirjas)
Expand Down Expand Up @@ -161,12 +162,12 @@ nirjas -i <target file>

## Tests

To run a test for Nirjas, go to the `/extractor` folder and use the command:
To run a test for Nirjas, execute the following script:

```sh
python3 testscript.py
python3 testScript.py
```
This will download all the test files into `languages/tests/TestFiles` folder and will run the tests as well.
This will download all the test files into `nirjas/languages/tests/TestFiles` folder and will run the tests as well.

## Documentation

Expand Down
28 changes: 13 additions & 15 deletions nirjas/languages/tests/test_c.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import unittest
import re, os
from languages import c
from binder import readSingleLine,readMultiLineDiff,contSingleLines
import os
from nirjas.languages import c
from nirjas.binder import readSingleLine,readMultiLineDiff,contSingleLines


class CTest(unittest.TestCase):

testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.c")

def test_output(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.c")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
sign = '//'
self.syntax_start = "/*"
self.syntax_end ='*/'
comment_single = c.readSingleLine(path,regex,sign)
comment_multiline = c.readMultiLineDiff(path,self.syntax_start,self.syntax_end)
comment_single = c.readSingleLine(self.testfile,regex,sign)
comment_multiline = c.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSinglelines = c.contSingleLines(comment_single)
self.assertTrue(comment_single)
self.assertTrue(comment_multiline)
self.assertTrue(comment_contSinglelines)



def test_outputFormat(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.c")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end = "*/"
sign = '//'
expected = c.cExtractor(path)
comment_single = readSingleLine(path,regex,sign)
comment_multiline = readMultiLineDiff(path,self.syntax_start,self.syntax_end)
expected = c.cExtractor(self.testfile)
comment_single = readSingleLine(self.testfile,regex,sign)
comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSinglelines = contSingleLines(comment_single)
file = path.split("/")
file = self.testfile.split("/")
output = {
"metadata": [{
"filename": file[-1],
Expand Down Expand Up @@ -65,9 +64,8 @@ def test_outputFormat(self):
self.assertEqual(output,expected)

def test_Source(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.c")
name = "source.txt"
newfile = c.cSource(path,name)
newfile = c.cSource(self.testfile,name)

self.assertTrue(newfile)

29 changes: 14 additions & 15 deletions nirjas/languages/tests/test_c_sharp.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import unittest
import re, os
from languages import c_sharp
from binder import readSingleLine,readMultiLineDiff,contSingleLines
import os
from nirjas.languages import c_sharp
from nirjas.binder import readSingleLine,readMultiLineDiff,contSingleLines


class CSharpTest(unittest.TestCase):

testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.cs")

def test_output(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.cs")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '//'
comment_single = c_sharp.readSingleLine(path,regex,sign)
comment_multiline = c_sharp.readMultiLineDiff(path,self.syntax_start,self.syntax_end)
comment_single = c_sharp.readSingleLine(self.testfile,regex,sign)
comment_multiline = c_sharp.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = c_sharp.contSingleLines(comment_single)

self.assertTrue(comment_single)
Expand All @@ -22,16 +23,15 @@ def test_output(self):


def test_outputFormat(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.cs")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '//'
expected = c_sharp.c_sharpExtractor(path)
comment_single = readSingleLine(path,regex,sign)
comment_multiline = readMultiLineDiff(path,self.syntax_start,self.syntax_end)
expected = c_sharp.c_sharpExtractor(self.testfile)
comment_single = readSingleLine(self.testfile,regex,sign)
comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = contSingleLines(comment_single)
file = path.split("/")
file = self.testfile.split("/")
output = {
"metadata": [{
"filename": file[-1],
Expand Down Expand Up @@ -64,8 +64,7 @@ def test_outputFormat(self):
self.assertEqual(output,expected)

def test_Source(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.cs")
name = "source.txt"
newfile = c_sharp.c_sharpSource(path,name)
newfile = c_sharp.c_sharpSource(self.testfile,name)

self.assertTrue(newfile)
self.assertTrue(newfile)
28 changes: 13 additions & 15 deletions nirjas/languages/tests/test_cpp.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import unittest
import re, os
from languages import cpp
from binder import readSingleLine,readMultiLineDiff,contSingleLines
import os
from nirjas.languages import cpp
from nirjas.binder import readSingleLine,readMultiLineDiff,contSingleLines

class CPPTest(unittest.TestCase):

testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.cpp")

def test_output(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.cpp")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '//'
comment_single = cpp.readSingleLine(path,regex,sign)
comment_multiline = cpp.readMultiLineDiff(path,self.syntax_start,self.syntax_end)
comment_single = cpp.readSingleLine(self.testfile,regex,sign)
comment_multiline = cpp.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = cpp.contSingleLines(comment_single)
self.assertTrue(comment_single)
self.assertTrue(comment_multiline)
Expand All @@ -21,16 +21,15 @@ def test_output(self):


def test_outputFormat(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.cpp")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '//'
expected = cpp.cppExtractor(path)
comment_single = readSingleLine(path,regex,sign)
comment_multiline = readMultiLineDiff(path,self.syntax_start,self.syntax_end)
expected = cpp.cppExtractor(self.testfile)
comment_single = readSingleLine(self.testfile,regex,sign)
comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = contSingleLines(comment_single)
file = path.split("/")
file = self.testfile.split("/")
output = {
"metadata": [{
"filename": file[-1],
Expand Down Expand Up @@ -66,8 +65,7 @@ def test_outputFormat(self):
self.assertEqual(output,expected)

def test_Source(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.cpp")
name = "source.txt"
newfile = cpp.cppSource(path,name)
newfile = cpp.cppSource(self.testfile,name)

self.assertTrue(newfile)
self.assertTrue(newfile)
25 changes: 12 additions & 13 deletions nirjas/languages/tests/test_css.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import unittest
import re, os
from languages import css
from binder import readSingleLine,readMultiLineDiff
import os
from nirjas.languages import css
from nirjas.binder import readMultiLineDiff


class CssTest(unittest.TestCase):

testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.css")

def test_output(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.css")
self.syntax_start = "/*"
self.syntax_end ='*/'
comment_multiline = css.readMultiLineDiff(path,self.syntax_start,self.syntax_end)
comment_multiline = css.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)

self.assertTrue(comment_multiline)



def test_outputFormat(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.m")
self.syntax_start = "/*"
self.syntax_end ='*/'
expected = css.cssExtractor(path)
comment_multiline = readMultiLineDiff(path,self.syntax_start,self.syntax_end)
file = path.split("/")
expected = css.cssExtractor(self.testfile)
comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
file = self.testfile.split("/")
output = {
"metadata": [{
"filename": file[-1],
Expand All @@ -44,8 +44,7 @@ def test_outputFormat(self):
self.assertEqual(output,expected)

def test_Source(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.css")
name = "source.txt"
newfile = css.cssSource(path,name)
newfile = css.cssSource(self.testfile,name)

self.assertTrue(newfile)
self.assertTrue(newfile)
29 changes: 14 additions & 15 deletions nirjas/languages/tests/test_go.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import unittest
import re, os
from languages import go
from binder import readSingleLine,readMultiLineDiff,contSingleLines
import os
from nirjas.languages import go
from nirjas.binder import readSingleLine,readMultiLineDiff,contSingleLines


class GoTest(unittest.TestCase):

testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.cs")

def test_output(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.java")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '//'
comment_single = go.readSingleLine(path,regex,sign)
comment_multiline = go.readMultiLineDiff(path,self.syntax_start,self.syntax_end)
comment_single = go.readSingleLine(self.testfile,regex,sign)
comment_multiline = go.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = go.contSingleLines(comment_single)
self.assertTrue(comment_single)
self.assertTrue(comment_multiline)
Expand All @@ -21,16 +22,15 @@ def test_output(self):


def test_outputFormat(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.go")
regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '//'
expected = go.goExtractor(path)
comment_single = readSingleLine(path,regex,sign)
comment_multiline = readMultiLineDiff(path,self.syntax_start,self.syntax_end)
expected = go.goExtractor(self.testfile)
comment_single = readSingleLine(self.testfile,regex,sign)
comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = contSingleLines(comment_single)
file = path.split("/")
file = self.testfile.split("/")
output = {
"metadata": [{
"filename": file[-1],
Expand Down Expand Up @@ -63,8 +63,7 @@ def test_outputFormat(self):
self.assertEqual(output,expected)

def test_Source(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.go")
name = "source.txt"
newfile = go.goSource(path,name)
newfile = go.goSource(self.testfile,name)

self.assertTrue(newfile)
self.assertTrue(newfile)
27 changes: 13 additions & 14 deletions nirjas/languages/tests/test_haskell.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import unittest
import re, os
from languages import haskell
from binder import readSingleLine,readMultiLineDiff,contSingleLines
import os
from nirjas.languages import haskell
from nirjas.binder import readSingleLine,readMultiLineDiff,contSingleLines


class HaskellTest(unittest.TestCase):

testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.hs")

def test_output(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.hs")
regex = r'''(\-\-\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "/*"
self.syntax_end ='*/'
sign = '--'
comment_single = haskell.readSingleLine(path,regex,sign)
comment_multiline = haskell.readMultiLineDiff(path,self.syntax_start,self.syntax_end)
comment_single = haskell.readSingleLine(self.testfile,regex,sign)
comment_multiline = haskell.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = haskell.contSingleLines(comment_single)
self.assertTrue(comment_single)
self.assertTrue(comment_multiline)
Expand All @@ -21,16 +22,15 @@ def test_output(self):


def test_outputFormat(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.hs")
regex = r'''(\-\-\s*[\w #\.()@+-_*\d]*)'''
self.syntax_start = "{-"
self.syntax_end = "-}"
sign = '--'
expected = haskell.haskellExtractor(path)
comment_single = readSingleLine(path,regex,sign)
comment_multiline = readMultiLineDiff(path,self.syntax_start,self.syntax_end)
expected = haskell.haskellExtractor(self.testfile)
comment_single = readSingleLine(self.testfile,regex,sign)
comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end)
comment_contSingleline = contSingleLines(comment_single)
file = path.split("/")
file = self.testfile.split("/")
output = {
"metadata": [{
"filename": file[-1],
Expand Down Expand Up @@ -63,9 +63,8 @@ def test_outputFormat(self):
self.assertEqual(output,expected)

def test_Source(self):
path = os.path.join(os.getcwd(),"languages/tests/TestFiles/textcomment.hs")
name = "source.txt"
newfile = haskell.haskellSource(path,name)
newfile = haskell.haskellSource(self.testfile,name)

self.assertTrue(newfile)

Loading

0 comments on commit 8709011

Please sign in to comment.