Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
eaed575
fix doctest output
imamnurby May 1, 2024
7efb244
[1030] refine docstring and implementation
imamnurby May 1, 2024
fde3229
[1030] refine test cases using setUp and tearDown method
imamnurby May 1, 2024
6fc2e42
[1029] refine docstring description and remove unused libraries
imamnurby May 1, 2024
0fd7f4e
fix bug in the VALID_JSON_STRUCTURE constant, refine testcases
imamnurby May 1, 2024
d234a04
refine docstring
imamnurby May 1, 2024
c994597
move out the test cases from run_test function, rename test class to …
imamnurby May 1, 2024
6a54fdd
fix docstring expected output
imamnurby May 1, 2024
e3b577d
improve test cases
imamnurby May 1, 2024
6c353b9
remove typing
imamnurby May 1, 2024
9ae63d5
refine docstring
imamnurby May 1, 2024
e901168
add a test case to check the payload
imamnurby May 1, 2024
e35882a
refine docstring
imamnurby May 1, 2024
999007e
rename unittest class
imamnurby May 1, 2024
9f93f4f
refine testcases
imamnurby May 1, 2024
1c4a053
refine docstring
imamnurby May 1, 2024
f141346
refine testcases
imamnurby May 1, 2024
6050eb0
refine docstring
imamnurby May 1, 2024
6dc6c56
refine testcases
imamnurby May 1, 2024
809f4cd
refine docstring
imamnurby May 1, 2024
8a76c49
refine testcases, add Raises in the docstring
imamnurby May 1, 2024
a72de9a
refine docstring
imamnurby May 1, 2024
4842b4f
refine testcases
imamnurby May 1, 2024
48b4b74
refine docstring
imamnurby May 1, 2024
52dc438
refine testcases
imamnurby May 1, 2024
bed6ad8
refine doctstring
imamnurby May 2, 2024
e6b8adf
refine testcases
imamnurby May 2, 2024
048d45c
refine docstring
imamnurby May 2, 2024
075897c
refine testcases
imamnurby May 2, 2024
5d79adb
refine docstring
imamnurby May 3, 2024
af2f47a
refine docstring and testcases
imamnurby May 3, 2024
3948747
refine docstring
imamnurby May 3, 2024
3c73dcf
refine testcases
imamnurby May 3, 2024
fd68ac1
remove unused import
imamnurby May 3, 2024
cef46b3
add import
imamnurby May 3, 2024
d0daeb0
refine docstring
imamnurby May 3, 2024
bcb42e4
refine testcases
imamnurby May 3, 2024
73469f4
refine docstring
imamnurby May 3, 2024
1f9d19a
refine docstring and testcases
imamnurby May 3, 2024
dbda3df
refine docstring and testcases
imamnurby May 3, 2024
62ece73
refine docstring
imamnurby May 3, 2024
f4f91f2
refine docstring
imamnurby May 4, 2024
3ea0517
refine testcases
imamnurby May 4, 2024
464cfd3
refine docstring
imamnurby May 4, 2024
c53df91
refine docstring
imamnurby May 4, 2024
5788154
refine testcases
imamnurby May 4, 2024
ff160e4
refine testcases
imamnurby May 4, 2024
ec8f2ef
refien docstring and testcases
imamnurby May 4, 2024
dc16c13
refine docstring
imamnurby May 4, 2024
6dbada6
refine docstring and testcases
imamnurby May 4, 2024
3e7cfc5
refine docstring
imamnurby May 4, 2024
04b0c12
refine testcases
imamnurby May 4, 2024
099cc79
refine testcases
imamnurby May 4, 2024
00b517b
refine docstring and testcases
imamnurby May 4, 2024
3b296da
refine docstring and testcases
imamnurby May 4, 2024
abc98d6
refine docstring and add statistics library
imamnurby May 4, 2024
fcfa0ae
refine testcases
imamnurby May 4, 2024
cb335b0
refine testcases, add Raises section in the docstring
imamnurby May 4, 2024
831b0dd
refine docstring and testcases, modify the implementation to use the …
imamnurby May 4, 2024
9a1f33b
refine docstring and testcases, add helper function to check mse value
imamnurby May 4, 2024
810293e
refine docstring and testcases
imamnurby May 4, 2024
e17b2fb
add docstring and refine testcases
imamnurby May 4, 2024
12eca2f
refine docstring and testcases
imamnurby May 4, 2024
fc358b9
refine docstring and testcases
imamnurby May 4, 2024
437bbe2
refine docstring and testcases
imamnurby May 4, 2024
f910eae
refine testcases and docstring
imamnurby May 5, 2024
0827422
refine docstring and testcases, add Raises
imamnurby May 5, 2024
2d6696a
refine docstring and move loading sql inside the function
imamnurby May 5, 2024
bea53e8
refine docstring and testcases
imamnurby May 5, 2024
ab7c50e
refine testcases and docstring
imamnurby May 6, 2024
9f5f78a
refine docstring and testcases
imamnurby May 6, 2024
0232eba
remove duplicate import statements and mock class
imamnurby May 6, 2024
5b48a67
add Requirements in the docstring
imamnurby May 6, 2024
c632a7a
remove print
imamnurby May 6, 2024
151f63e
remove print
imamnurby May 6, 2024
3335ec7
refine docstring
imamnurby May 6, 2024
f4648eb
fix implementation and refine testcases
imamnurby May 6, 2024
8ab7d08
refine docstring and testcases
imamnurby May 6, 2024
3b917e2
refine testcases
imamnurby May 6, 2024
c40f70f
refine docstring
imamnurby May 6, 2024
376fd52
refine and add more testcases, add missing import
imamnurby May 6, 2024
a79c547
refine docstring and testcases
imamnurby May 6, 2024
0bcdfa3
update the docstring
imamnurby May 6, 2024
a4299b5
refine testcases and docstring
imamnurby May 6, 2024
8911a3e
fix duplicate runner method, rename test class
imamnurby May 6, 2024
b539253
refine docstring and testcases
imamnurby May 6, 2024
86df211
refine docstring and testcases
imamnurby May 6, 2024
ebe6e10
refine docstring and testcases
imamnurby May 6, 2024
127b5aa
remove multiple import
imamnurby May 6, 2024
d354394
remove multiple import
imamnurby May 6, 2024
d2477c1
refine docstring
imamnurby May 6, 2024
bf77ef6
update example
imamnurby May 6, 2024
6da3bfe
remove duplicate import
imamnurby May 6, 2024
3d1d11e
remove comments
imamnurby May 6, 2024
8ab8219
remove duplicate import
imamnurby May 6, 2024
6c24263
update import
imamnurby May 6, 2024
248f4e4
add Raises section, make the testcases more deterministic
imamnurby May 6, 2024
5d732f3
change randint to random
imamnurby May 6, 2024
228e847
make the test more specific and deterministic
imamnurby May 6, 2024
687aa93
remove constant
imamnurby May 6, 2024
9c94bfd
refine docstring and testcases
imamnurby May 7, 2024
876026a
add Requirements in the docstring
imamnurby May 7, 2024
03157a0
remove explanation in Requirments
imamnurby May 7, 2024
8bbd4b8
fix indentation
imamnurby May 7, 2024
6285360
separte testcases
imamnurby May 7, 2024
fd604d0
move constant as the default param
imamnurby May 7, 2024
5d9af2d
Move THRESHOLD to optional param
imamnurby May 7, 2024
ade40b0
add type of K
imamnurby May 7, 2024
cb26fc2
move SALTH_LENGTH to optional param
imamnurby May 7, 2024
7702642
move DATE_FORMAT to optional param
imamnurby May 7, 2024
943584c
fix wrong argument in datetime.strptime in the testcase
imamnurby May 7, 2024
fb24d18
move VALID_JSON_STRUCTURE and EMAIL_REGEX to optional param
imamnurby May 7, 2024
cac15bc
Add default values in the docstring
imamnurby May 7, 2024
4222532
fix testcases
imamnurby May 7, 2024
afcb5ce
modify example in the docstring
imamnurby May 7, 2024
e4de8b0
remove unused import
imamnurby May 7, 2024
765695e
fix the example in the docstring
imamnurby May 7, 2024
37a0107
fix the example in the docstring
imamnurby May 7, 2024
7e9af83
add .db in check_test_wo_doc
imamnurby May 7, 2024
fad8c1f
add subprocess in check_test_wo_doc
imamnurby May 7, 2024
d840f31
separate the testcase to check the number of updated hash and the cor…
imamnurby May 7, 2024
3d40647
refine the testcases
imamnurby May 7, 2024
f4d3de0
refine testcases
imamnurby May 7, 2024
25062ec
rename files
imamnurby May 7, 2024
60a6070
cleanup files
imamnurby May 7, 2024
a076144
update script
imamnurby May 7, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refine docstring and testcases
  • Loading branch information
imamnurby committed May 3, 2024
commit dbda3df235fbaf6bd4682e2478ee47d96b2ce71f
119 changes: 55 additions & 64 deletions data/raw/f_1014_zhihan.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
import configparser
import os
import sys
import shutil

# Constants
ARCHIVE_DIR = '/home/user/archive'

def f_1014(config_file_path):
def f_1014(config_file_path, archieve_dir ='/home/user/archive'):
"""
Archive a specified project directory into a ZIP file.
Archive a specified project directory into a ZIP file based on the configuration specified in a config file.

This function reads a configuration file to get the project directory and then archives this directory
into a ZIP file. The name of the ZIP archive will be the same as the
project directory's basename, and it will be stored in a predefined archive directory.
This function reads a configuration file to determine the project directory and archives this directory into a ZIP file.
The ZIP file's name will be the project directory's basename, stored in the specified archive directory.

Configuration File Format:
[Project]
directory=path_to_project_directory

Input:
- config_file_path (str): Path to the configuration file.
Parameters:
- config_file_path (str): Path to the configuration file. The file must exist and be readable.
- archive_dir (str, optional): Path to the directory where the ZIP archive will be stored. Defaults to '/home/user/archive'.

Output:
- Returns True if the ZIP archive is successfully created, otherwise raises an exception.
Returns:
- bool: True if the ZIP archive is successfully created, otherwise an exception is raised.

Requirements:
- configparser
- os
- sys
- shutil

Constants:
- ARCHIVE_DIR: Directory where the ZIP archive will be stored.
Raises:
- FileNotFoundError: If the `config_file_path` does not exist or the specified project directory does not exist.
- Exception: If the ZIP archive cannot be created.

Example:
>>> f_1014("/path/to/config.ini")
Expand All @@ -43,9 +35,9 @@ def f_1014(config_file_path):
project_dir = config.get('Project', 'directory')

if not os.path.isdir(project_dir):
raise Exception(f'Directory {project_dir} does not exist.')
raise FileNotFoundError(f'Directory {project_dir} does not exist.')

archive_file = f'{ARCHIVE_DIR}/{os.path.basename(project_dir)}.zip'
archive_file = f'{archieve_dir}/{os.path.basename(project_dir)}.zip'

# Using shutil to create the zip archive
shutil.make_archive(base_name=os.path.splitext(archive_file)[0], format='zip', root_dir=project_dir)
Expand All @@ -56,66 +48,65 @@ def f_1014(config_file_path):
return True

import unittest
import tempfile
import shutil
import os
import sys
import configparser

class TestF962Function(unittest.TestCase):
class TestCases(unittest.TestCase):

def setUp(self):
# Path to the test data directory
self.test_data_dir = "/mnt/data/test_data"
# Setup a temporary directory for the configuration files and another for the archive output
self.test_data_dir = tempfile.mkdtemp()
self.archive_dir = tempfile.mkdtemp()

# Example valid configuration file setup
self.valid_config_path = os.path.join(self.test_data_dir, "valid_config.ini")
config = configparser.ConfigParser()
config['Project'] = {'directory': self.test_data_dir}
with open(self.valid_config_path, 'w') as configfile:
config.write(configfile)

# Invalid directory config
self.invalid_config_path = os.path.join(self.test_data_dir, "invalid_config.ini")
config['Project'] = {'directory': '/path/to/nonexistent/directory'}
with open(self.invalid_config_path, 'w') as configfile:
config.write(configfile)

def tearDown(self):
# Remove temporary directories after each test
shutil.rmtree(self.test_data_dir)
shutil.rmtree(self.archive_dir)

def test_valid_project_directory(self):
# Set CONFIG_FILE to point to a valid config file
refined_function.CONFIG_FILE = os.path.join(self.test_data_dir, "valid_config.ini")

# Asserting that the function returns True (archive is successfully created)
self.assertTrue(f_1014())
# Testing with a valid project directory
result = f_1014(self.valid_config_path, self.archive_dir)
self.assertTrue(result)

def test_invalid_project_directory(self):
# Set CONFIG_FILE to point to an invalid config file (non-existent project directory)
refined_function.CONFIG_FILE = os.path.join(self.test_data_dir, "invalid_dir_config.ini")

# Asserting that the function raises an exception due to the invalid directory
with self.assertRaises(Exception) as context:
f_1014()
self.assertIn("Directory", str(context.exception))

def test_empty_project_directory(self):
# Set CONFIG_FILE to point to an empty config file (empty project directory path)
refined_function.CONFIG_FILE = os.path.join(self.test_data_dir, "empty_config.ini")

# Asserting that the function raises an exception due to the empty directory path
with self.assertRaises(Exception) as context:
f_1014()
self.assertIn("Directory", str(context.exception))

# Testing with a non-existent project directory
with self.assertRaises(FileNotFoundError):
f_1014(self.invalid_config_path, self.archive_dir)

def test_archive_creation(self):
# Set CONFIG_FILE to point to a valid config file
refined_function.CONFIG_FILE = os.path.join(self.test_data_dir, "valid_config.ini")

# Run the function to create the archive
f_1014()

# Asserting that the archive file is created
archive_file = os.path.join(refined_function.ARCHIVE_DIR, "sample_project_1.zip")
f_1014(self.valid_config_path, self.archive_dir)
archive_file = os.path.join(self.archive_dir, os.path.basename(self.test_data_dir) + '.zip')
self.assertTrue(os.path.isfile(archive_file))

def test_archive_content(self):
# Set CONFIG_FILE to point to a valid config file
refined_function.CONFIG_FILE = os.path.join(self.test_data_dir, "valid_config.ini")

# Run the function to create the archive
f_1014()

# Asserting that the archive file contains the expected content
archive_file = os.path.join(refined_function.ARCHIVE_DIR, "sample_project_1.zip")
# Adding a sample file to the project directory to check archive contents later
sample_file_path = os.path.join(self.test_data_dir, "sample_file.txt")
with open(sample_file_path, 'w') as f:
f.write("Hello, world!")
f_1014(self.valid_config_path, self.archive_dir)
archive_file = os.path.join(self.archive_dir, os.path.basename(self.test_data_dir) + '.zip')
content = os.popen(f"unzip -l {archive_file}").read()
self.assertIn("sample_file.txt", content)

def run_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestF962Function))
suite.addTest(unittest.makeSuite(TestCases))
runner = unittest.TextTestRunner()
runner.run(suite)
if __name__ == "__main__":
Expand Down