Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions rflint/rflint.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,23 @@ def run(self, args):

self.counts = { ERROR: 0, WARNING: 0, "other": 0}

self.filetypes = [f".{ft}" for ft in self.args.filetypes.split(',')]
supported_file_types = [".robot", ".resource", ".tsv", ".txt", ".rst"]
for ft in self.filetypes:
if ft not in supported_file_types:
sys.stderr.write(f"rflint: File extension {ft} is not supported")
return -1

for filename in self.args.args:
if not (os.path.exists(filename)):
sys.stderr.write("rflint: %s: No such file or directory\n" % filename)
continue
if os.path.isdir(filename):
self._process_folder(filename)
else:
self._process_file(filename)
_, ext = os.path.splitext(filename)
if ext.lower() in self.filetypes:
self._process_file(filename)

if self.counts[ERROR] > 0:
return self.counts[ERROR] if self.counts[ERROR] < 254 else 255
Expand Down Expand Up @@ -143,8 +152,8 @@ def _process_folder(self, path):

def _process_files(self, folder, filenames):
for filename in filenames:
name, ext = os.path.splitext(filename)
if ext.lower() in (".robot", ".txt", ".tsv", ".resource"):
_, ext = os.path.splitext(filename)
if ext.lower() in self.filetypes:
self._process_file(os.path.join(folder, filename))

def _process_file(self, filename):
Expand Down Expand Up @@ -266,6 +275,12 @@ def parse_and_process_args(self, args):
"\n"
"If you give a directory as an argument, all files in the directory\n"
"with the suffix .txt, .robot, .resource, or .tsv will be processed. \n"
"You can explicitly provide file types which you want to run\n"
"with option --filetypes or -t. Defaults are robot and resource.\n"
"\n"
"For example: '--filetypes robot,resource' will ignore all files\n"
"with extensions other than .robot or .resource.\n"
"\n"
"With the --recursive option, subfolders within the directory will \n"
"also be processed."
)
Expand All @@ -286,6 +301,9 @@ def parse_and_process_args(self, args):
parser.add_argument("--format", "-f",
help="Define the output format",
default='{severity}: {linenumber}, {char}: {message} ({rulename})')
parser.add_argument("--filetypes", "-t",
help="Select file extensions to scan separated by comma",
default='robot,resource')
parser.add_argument("--version", action="store_true", default=False,
help="Display version number and exit")
parser.add_argument("--verbose", "-v", action="store_true", default=False,
Expand Down
2 changes: 2 additions & 0 deletions test_data/acceptance/filetypes/test.resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Invalid

3 changes: 3 additions & 0 deletions test_data/acceptance/filetypes/test.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** Test Cases ***
Simple Test Case
Pass Execution Everything's fine
3 changes: 3 additions & 0 deletions test_data/acceptance/filetypes/test.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** Test Cases ***
Simple Test Case
Pass Execution Everything's fine
3 changes: 3 additions & 0 deletions test_data/acceptance/filetypes/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** Test Cases ***
Simple Test Case
Pass Execution Everything's fine
104 changes: 104 additions & 0 deletions tests/acceptance/filetypes.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
*** Settings ***
Documentation Check if rflint reads supported file formats
Library OperatingSystem
Library Process
Library String
Resource SharedKeywords.robot


*** Test Cases ***
All Supported File Types
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
robot resource tsv

.robot And .resource Supported File Types
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
robot resource

.resource And .tsv Supported File Types
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
resource tsv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misaligned

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it on purpose, please look at the whole file. But I can revert it if it looks strange. What do you think?

Copy link

@bhirsz bhirsz Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, thanks to this format it's easy to see that you're testing this or that file format combination. But maybe you could use this approach?

*** Test Cases ***    
Test Supported File Types    
[Template]      Run Rflint And Verify There Are No Errors For Supported File Types    
robot  resource  tsv    
robot  resource    
       resource    tsv    
robot              tsv    
robot    
      resource    
    

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, another approach is to use arguments embedded in keyword name. I will think which one is the best for this use.


.robot And .tsv Supported File Types
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
robot tsv

Only .robot Supported File Type
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
robot

Only .resource Supported File Type
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
resource

Only .tsv Supported File Type
[Template] Run Rflint And Verify There Are No Errors For Supported File Types
tsv

Only .pdf Unsupported File Type
[Template] Run Rflint And Verify That Unsupported File Types Returned Errors
pdf

Specific .txt File With .robot Provided File Type
[Template] Run Rflint And Verify There Are No Output For Not Matching File Types
test_data/acceptance/filetypes/test.txt robot

Specific .robot File With .resource Provided File Type
[Template] Run Rflint And Verify There Are No Output For Not Matching File Types
test_data/acceptance/filetypes/test.robot resource

Specific .resource File With .robot And .tsv Provided File Type
[Template] Run Rflint And Verify There Are No Output For Not Matching File Types
test_data/acceptance/filetypes/test.resource robot tsv

Specific .tsv File With .robot And .resource Provided File Type
[Template] Run Rflint And Verify There Are No Output For Not Matching File Types
test_data/acceptance/filetypes/test.tsv robot resource


*** Keywords ***
Run Rflint And Verify There Are No Errors For Supported File Types
[Arguments] @{extensions}
${file_types} Parse File Types @{extensions}
Run rf-lint with the following options:
... --filetypes ${file_types}
... test_data/acceptance/filetypes
FOR ${file_type} IN @{extensions}
Should Contain ${result.stdout} test.${file_type}
END
Should Be Empty ${result.stderr}

Run Rflint And Verify That Unsupported File Types Returned Errors
[Arguments] @{extensions}
${file_types} Parse File Types @{extensions}
Run rf-lint with the following options:
... --filetypes ${file_types}
... test_data/acceptance/filetypes
FOR ${file_type} IN @{extensions}
Should Contain ${result.stderr} rflint: File extension .${file_type} is not supported
END
Should Be Empty ${result.stdout}

Run Rflint And Verify There Are No Output For Not Matching File Types
[Arguments] ${path_to_file} @{extensions}
${file_types} Parse File Types @{extensions}
Run rf-lint with the following options:
... -t ${file_types}
... ${path_to_file}
FOR ${file_type} IN @{extensions}
Should Be Empty ${result.stdout} ${EMPTY}
Should Be Empty ${result.stderr} ${EMPTY}
END
Should Be Empty ${result.stderr}

Parse File Types
[Arguments] @{filetypes}
${types} Set Variable ${EMPTY}
FOR ${index} ${file_type} IN ENUMERATE @{filetypes}
${types} Run Keyword If ${index}==${0}
... Set Variable ${file_type}
... ELSE
... Set Variable ${types},${file_type}
END
Log Provided filetypes: ${types}
[Return] ${types}