WIP Add tests for gradle and json
This commit is contained in:
parent
fd84063edc
commit
ca3db5efe9
6 changed files with 32 additions and 13 deletions
|
@ -18,7 +18,7 @@ apply plugin: "kotlinx-serialization"
|
||||||
|
|
||||||
|
|
||||||
group = "org.domaindrivenarchitecture.provs"
|
group = "org.domaindrivenarchitecture.provs"
|
||||||
version = "0.17.1"
|
version = "0.17.1-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
@ -4,11 +4,8 @@ from file_handlers import FileHandler
|
||||||
def init_project():
|
def init_project():
|
||||||
# validate_values()
|
# validate_values()
|
||||||
version = Version.from_file('build.gradle')
|
version = Version.from_file('build.gradle')
|
||||||
v2 = Version.from_file('package.json')
|
version.increment(ReleaseLevel.SNAPSHOT)
|
||||||
print(type(version.file_handler))
|
version.to_file()
|
||||||
print(type(v2.file_handler))
|
|
||||||
# version.increment(ReleaseLevel.SNAPSHOT)
|
|
||||||
# version.write()
|
|
||||||
print(version.get())
|
print(version.get())
|
||||||
|
|
||||||
def prepare_release():
|
def prepare_release():
|
||||||
|
@ -39,6 +36,12 @@ class Version():
|
||||||
|
|
||||||
return inst
|
return inst
|
||||||
|
|
||||||
|
def to_file(self):
|
||||||
|
if self.file_handler is None:
|
||||||
|
raise Exception('Version was not created by from_file method.')
|
||||||
|
else:
|
||||||
|
self.file_handler.write(self.get())
|
||||||
|
|
||||||
def increment(self, level: ReleaseLevel):
|
def increment(self, level: ReleaseLevel):
|
||||||
self.is_snapshot = False
|
self.is_snapshot = False
|
||||||
match level:
|
match level:
|
||||||
|
|
|
@ -24,7 +24,7 @@ class FileHandler(ABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def write(self):
|
def write(self, version_string):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class JsonFileHandler(FileHandler):
|
class JsonFileHandler(FileHandler):
|
||||||
|
@ -39,10 +39,10 @@ class JsonFileHandler(FileHandler):
|
||||||
version = [int(x) for x in json_version.split('.')]
|
version = [int(x) for x in json_version.split('.')]
|
||||||
return version, is_snapshot
|
return version, is_snapshot
|
||||||
|
|
||||||
def write(self):
|
def write(self, version_string):
|
||||||
with open(self.config_file_path, 'r+') as json_file:
|
with open(self.config_file_path, 'r+') as json_file:
|
||||||
json_data = json.load(json_file)
|
json_data = json.load(json_file)
|
||||||
json_data['version'] = self.get()
|
json_data['version'] = version_string
|
||||||
json_file.seek(0)
|
json_file.seek(0)
|
||||||
json.dump(json_data, json_file, indent=4)
|
json.dump(json_data, json_file, indent=4)
|
||||||
json_file.truncate()
|
json_file.truncate()
|
||||||
|
@ -72,10 +72,10 @@ class GradleFileHandler(FileHandler):
|
||||||
|
|
||||||
return version, is_snapshot
|
return version, is_snapshot
|
||||||
|
|
||||||
def write(self):
|
def write(self, version_string):
|
||||||
with open(self.config_file_path, 'r+') as gradle_file:
|
with open(self.config_file_path, 'r+') as gradle_file:
|
||||||
gradle_contents = gradle_file.read()
|
gradle_contents = gradle_file.read()
|
||||||
version_substitute = re.sub("\nversion = .*\n", f'\nversion = "{self.get()}"\n', gradle_contents)
|
version_substitute = re.sub("\nversion = .*\n", f'\nversion = "{version_string}"\n', gradle_contents)
|
||||||
gradle_file.seek(0)
|
gradle_file.seek(0)
|
||||||
gradle_file.write(version_substitute)
|
gradle_file.write(version_substitute)
|
||||||
gradle_file.truncate()
|
gradle_file.truncate()
|
||||||
|
|
2
test/config.gradle
Normal file
2
test/config.gradle
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
version = "12.4.678"
|
3
test/config.json
Normal file
3
test/config.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"version": "123.123.456"
|
||||||
|
}
|
|
@ -23,3 +23,14 @@ def test_version():
|
||||||
|
|
||||||
version.increment(ReleaseLevel.MAJOR)
|
version.increment(ReleaseLevel.MAJOR)
|
||||||
assert version.get() == "2.0.0"
|
assert version.get() == "2.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
def test_gradle():
|
||||||
|
# validate_values()
|
||||||
|
version = Version.from_file('build.gradle')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
version.increment(ReleaseLevel.SNAPSHOT)
|
||||||
|
version.to_file()
|
||||||
|
print(version.get())
|
Loading…
Reference in a new issue