Skip to content

Commit

Permalink
Change: use tmp_dirs in test_deprecate_vts due to file_type change
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHargarter committed Jul 8, 2024
1 parent de8d0b7 commit 2c291d1
Showing 1 changed file with 57 additions and 55 deletions.
112 changes: 57 additions & 55 deletions tests/standalone_plugins/test_deprecate_vts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,90 @@
# pylint: disable=protected-access
import unittest
from pathlib import Path
from tests.plugins import TemporaryDirectory

from tests.plugins import TemporaryDirectory
from troubadix.standalone_plugins.deprecate_vts import (
deprecate,
parse_args,
DeprecatedFile,
_get_summary,
_finalize_content,
update_summary,
get_files_from_path,
_get_summary,
deprecate,
filter_files,
get_files_from_path,
parse_args,
update_summary,
)


class ParseArgsTestCase(unittest.TestCase):
def test_parse_args(self):
testfile = "testfile.nasl"
output_path = "attic/"
reason = "NOTUS"

args = parse_args(
[
"--files",
testfile,
"--output-path",
output_path,
"--deprecation-reason",
reason,
]
)
self.assertEqual(args.files, [Path(testfile)])
self.assertEqual(args.output_path, Path(output_path))
self.assertEqual(args.deprecation_reason, reason)

def test_mandatory_arg_group_both(self):
testfile = "testfile.nasl"
output_path = "attic/"
input_path = "nasl/common"
reason = "NOTUS"

with self.assertRaises(SystemExit):
parse_args(
with TemporaryDirectory() as out_dir:
args = parse_args(
[
"--files",
testfile,
"--output-path",
output_path,
"--input-path",
input_path,
str(out_dir),
"--deprecation-reason",
reason,
]
)
self.assertEqual(args.files, [Path(testfile)])
self.assertEqual(args.output_path, out_dir)
self.assertEqual(args.deprecation_reason, reason)

def test_mandatory_arg_group_both(self):
testfile = "testfile.nasl"
reason = "NOTUS"

with (
TemporaryDirectory() as out_dir,
TemporaryDirectory() as in_dir,
):
with self.assertRaises(SystemExit):
parse_args(
[
"--files",
testfile,
"--input-path",
str(in_dir),
"--deprecation-reason",
reason,
"--output-path",
str(out_dir),
]
)

def test_invalid_reason(self):
output_path = "attic/"
input_path = "nasl/common"
reason = "foo"
with self.assertRaises(SystemExit):
parse_args(
[
"--output-path",
output_path,
"--input-path",
input_path,
"--deprecation-reason",
reason,
]
)

with TemporaryDirectory() as out_dir, TemporaryDirectory() as in_dir:
with self.assertRaises(SystemExit):
parse_args(
[
"--output-path",
str(out_dir),
"--input-path",
str(in_dir),
"--deprecation-reason",
reason,
]
)

def test_mandatory_arg_group_neither(self):
output_path = "attic/"
reason = "NOTUS"
with self.assertRaises(SystemExit):
parse_args(
[
"--output-path",
output_path,
"--deprecation-reason",
reason,
]
)
with TemporaryDirectory() as out_dir:
with self.assertRaises(SystemExit):
parse_args(
[
"--output-path",
str(out_dir),
"--deprecation-reason",
reason,
]
)


NASL_CONTENT = (
Expand Down

0 comments on commit 2c291d1

Please sign in to comment.